I have a multidimensional array of arrays (source below), where my keys and values are arbitrary strings. I want to create a new array (desired below), where the hierarchy stays the same, but every …
Tag: arrays
php array sorting with accents
I am using this to sort according to last name: But – when in last name is accent, e.g. Šiko, Áron, etc, these names are at the end. How can I sort it properly? Answer Use multi-byte string functions. There is a function called strcoll which seems to suit your needs. More info: On how to sort an array of
Filter array to retain rows with smallest element count and unique first and last elements
I want to remove rows from my array so that my result is an array that contains rows with unique first and last elements. If two (or more) rows have the same first and last value, I want to preserve the row with the lowest element count. Say I have the following array: What I want is to remove all
Convert list into an array using php. How?
I have a function called listelements(), which outputs text like <li>text1</li><li>text2</li>. I have more than 500 elements. Now I want to convert it into an array. Can anyone help me? Thanks. Note: I’m using php Update: The thing i want to achieve is alphabetical navigation. As of now my function displays links in list order. Instead of that i want
Merge two indexed arrays of indexed arrays based on first column value
I have two arrays like this: How can I merge these two arrays without looping? Is there any php functionality available for this? I need this kind of output: Answer You can use the PHP function array_merge_recursive. See the example:
Combine and transpose multiple single-dimensional arrays into a single multi-dimensional array
I have three single-dimensional arrays and I need to combine them into one 3-dimensional array where each array in the new array contains one element of each of the three original arrays. I know how to do this using a simple loop but I was wondering if there is a faster / built-in way of doing this. here is an
Transpose 2d array, join second level with commas, and join first level with pipes
I have the following two-dimensional array: I want to convert columns to rows then reduce the matrix to a string like the following: Answer I’m assuming that you have this array: In which case, you can do this: See it working
How to search in an array with preg_match?
How do I search in an array with preg_match? Example: Answer In this post I’ll provide you with three different methods of doing what you ask for. I actually recommend using the last snippet, since it’s easiest to comprehend as well as being quite neat in code. How do I see what elements in an array that matches my regular
Array of PHP Objects
So I have been searching for a while and cannot find the answer to a simple question. Is it possible to have an array of objects in PHP? Such as: For some reason I have not been able to find the answer anywhere. I assume it is possible but I just need to make sure. Answer The best place to
array_uintersect() gives unexpected results when callback only returns 0 or 1
I have a custom callback in my array_uintersect() call because I need to case-sensitively compare strings in two elements while comparing rows between two multi-dimensional arrays. OUTPUT I can’t understand why this code doesn’t produce the correct output which should be an array with “B”, “C” and “D” elements, because only “A” element is different from $vieja to $nueva… if