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: arrays
How to sum up property string length by ID using PHP in a JSON array
I am trying to sum up the character count(total string length) of all the characters contained in the various “info” properties by “user_id”. I am trying to have a situation where USER-ID A001 has 300 total characters in INFO I am hoping someone can point me in the right direction. Below is my code snippet: MY PHP Answer Use an
How to check the key of next index of arrays in PHP?
I have an PHP array : I want to check the keys of each array and if not match need to add it on every array. Expecting output like: If the key is not exist need to add the key with value zero. Is that possible? I tried with array_key_exists() function… But I’m not sure where I want to check,
How use array_map for order by word in php
I have this two-dimensional array And I would like this result: I am a beginner, so there may be things that are not done this way. Please understand 😉 I know how to run two foreach one inside the other and look for matches, but I think an array map would be faster and cleaner, right? Maybe I’m wrong about
Extract Json data from a countries.csv file on github, and create a seperate array of timezones
Country.csv this is countries.csv file, and i want to extract all the timezones from it, which is its 14th colomn, and the data in there is not properly json formatted. I’m trying to parse the json but it failed. Actually, I want to create an array of timezones like this what i’m doing, is this in AppHttpControllersTestController::class is this Answer
merge two equal structural multi-arrays with different data
i can’t believe that i can’t find a solution to this seemingly simple problem, and i tried everything. i have two multi arrays: the first one: the second one has the exact same structure, but with new data: what i need mergin both multi-arrays is this result: but i can’t get this result with any common php function: array_merge: it
Sort big array based by matching small array in php
I have an array- I want to resort this array dynamically to I have tried to find out the subarray based on which I know exactly from where to re-sort This has given me the output – Now I want to use this sub-array as the identifier to resort to the main array. Basically this sub-array will be the resort
How to merge array with custom value in laravel?
I need help to concatenate 2 arrays with custom values, I’ve used tried array_merge() and array_combine(), the result is always not same with what I want please help me guys Array 1 Array 2 I want the output be like this how to get the result like that Answer There isn’t any function that will automatically give you the result
Php array to pow numbers revers function problem
When I run the code above, I convert 24 sample data into a folded number and print it. Then when I want to call the numbers from the database and convert them back to strings, some of them seem wrong. Result: Reverse engineering is required. There is a problem with the number 30 in the aiflag2array function. The array2aiflag function
How can I convert from a{a{} b{}} to a[a[],b[]] using php preg_match?
How can I convert the above structure to the following result. I tried many patterns, but failed. I tried with regex pattern and explode function. I Failed in Recursive function. I want to get the output as array or json. How can i do it.Thanks…. Answer An approach in two steps: the first checks the whole string syntax with a