Here is the thing, I have an array that I’d like to reorder by every 3rd item. So it’s 1st, 4th, 7th and then 2nd, 5th, 8th and 3rd, 6th, 9th. from this: $items = array(‘1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9’); to this: $reordered_items = array(‘1′,’4′,’7′,’2′,’5′,’8′,’3′,’6′,’9’); Or it can be 3 separate arrays as well. Like this: [‘1’, ‘4’, ‘7’] [‘2’, ‘5’, ‘8’] [‘3’, ‘6’,
Tag: algorithm
Add element to listnode in PHP
If i have a listnode with the following defination How can i add an element to the end of the listnode and thus add int[i] elements by interation? Answer
Unusual data grouping / transformation
I’m struggling with an algorithmic problem how go transform or group data to get specified output. My input is a bunch of messages in given order (from newest to oldest): Desired output after transformation: So as you can see, each occurrence of the is_author parameter creates a new group that collects messages from this author ? Is there any efficient
PHP OpenSSL encrypt with DES-ECB algorithm unexpected output
I’ve tried to encrypt the value with DES-ECB via PHP 7.4 (Laravel) and OpenSSL, and I try the online tool https://emvlab.org/descalc/ to encrypt value, the result was the expected. key: 96187BBAB2BD19ACF899B74FB4E37972 Input Data: F01DCCE40F8C365ADE0A7DC03BC11DDE The encrypted data is 355A627E977D8ECF4953C98D801E472F on online tool. https://emvlab.org/descalc/?key=96187BBAB2BD19ACF899B74FB4E37972&iv=0000000000000000&input=f01dcce40f8c365ade0a7dc03bc11dde&mode=ecb&action=Encrypt&output=D5131A2B35766D371420F679F15969FF When the next code written in PHP I can’t replicate the result: Is there a way to
Separate date to several intervals
I’ve got an array like the following : And another array : I would like to create a new $array3 that removes the intervals from $array2 in $array1 to give the following result : As you can see, in $array3 2 new entries were added to remove the interval used in $array2. I don’t know how can I tackle an
PHP topological sort
LIST: controller name => priority:required controllers sorted and expected output: First sort by priority, then reorder based on required controllers to be loaded before. ensure not to be stuck in an infinite loop due to controllers requiring each other. I assume I’ll need something like this: Please help solve this with these steps: Remove infinite loop controllers (ex: controller_loopexit1 &
Get dependencies Ids Algorithm
I have this problem and I came out with a solution but what is the best way to solve this problem ? Thank you in advance. Given an array of strings and an array of tasks you need to return a sorted array with tasks and dependencies tasks ids. Example: Expected output: So far this is the solution I built,
Create Array From Key
Thank you in advance. Is there any way to create a multidimensional array from key names. Transform to this array. Thank you ! Answer Try my code (I used the reference operator “&” to get the successive inner arrays): Input array: php code: Result array:
How to generate a number pattern with given start and end value?
How can i generate a number pattern like this using php? a. Start = 1, End = 3 123 231 312 b. Start = 2 , End = 7 234567 345672 456723 567234 672345 723456 UPDATE: I tried this code: and get this output: But how to show the rest numbers? Answer you can try this algorithm:
Javascript and PHP quiz based on the questions which are in the database
I’m developing an online quiz that would let the user answer questions by clicking on a few radio buttons. I want the program to use the questions that are in the database. I’ve already created the …