i have array like this 1, 1 => ‘php’, 2 => 11, 3 => 11, 4 => 11, …
Tag: multidimensional-array
PHP – Concatenate / cascade multidimensional array keys
I’ve realized I need to stop banging my head and ask for help… I have the following array: I’m trying to collapse / cascade the keys into a one-dimension array like so: I could use nested loops, but the array will be an undefined number of dimensions. This is the closest I’ve gotten: Any ideas? Answer I think this should
Combine two arrays into a single array based on a common column value
I am trying to combine two arrays while respecting their shared value. My expected output: I have made a try by My output is: How can I combine the key value inside same array? or how can I bring the expected output? Note: I am trying for value instead of key ref: PHP Array Merge two Arrays on same key
Group row data within a 2d array based on a single column and push unique data into respective subarrays
I need to group data in a multidimensional array data which can be related on a single column entry_id. In addition to the entry_id there are other columns that will also be identical in other related rows (ic, name, and residency). While grouping, these data points can simply be overwritten — in other words, I don’t need to collect multiple
php sort multidimentional array by custom order
Sorting an multidimensional array by one of its key value (asc or desc) is asked too many times. but I’ve not found any solution for my problem where you have to sort a multidimensional array by one of its key value in predefined custom order. take an array for example and to sort this array by subkey ‘id’ by the
Filter multidimensional array by lowest price
I’m working with an array that I’d like to filter so it only contains the lowest prices per key. So 50 would only have one unit, same with 100, and that unit would be the lowest price. Here’s an example of what I’m working with: I wanted to avoid doing this with a complicated foreach loop, so I thought an
Multidimensional PHP array – Key exists
I want a function that will return TRUE or FALSE based on if a given key exists in a multidimensional array in PHP. I haven’t been able to figure out a recursive function to perform this action. A sample of what this could do: Answer This is where a recursive function comes in handy. Note that this can take some
array_push is replacing the variables instead of adding them to the end
Does anyone see an issue? Array push is just replacing variables instead of adding them. The variables of $fname, $lname, and $gender are defined by the user in a form. I want the variables to simply be added to the end of the array instead of being replaced. Any responses are appreciated. Answer if $info[“First_Names”] ,$info[“Last_Names”] ,$info[“Gender”] are arrays ,I
Check if specific array key exists in multidimensional array – PHP
I have a multidimensional array e.g. (this can be many levels deep): I am trying to loop through it to see if a certain key exists: But it finds nothing. Is there an error in the loop? Answer I played with your code to get it working :
Convert array objects to string and separate the values
I have the following result What i want is to separate the object array values using a comma and return as a string, so as to have this result: I have tried the following This return : How best can this be achieved? Answer You are missing the fact that you are dealing with an array of objects. Looks like