Home > Article > Backend Development > Convert a simple two-dimensional array into a one-dimensional array
In our work, we often need to convert two-dimensional arrays into one-dimensional arrays. Then we need to loop it out. In fact, sometimes we can use some tricks to achieve it with the help of PHP's built-in functions, but what I'm talking about is just a simple two-dimensional array $arr= array('name'=>array(' a'=>'abc','b'=>'bcd','c'=>'cde')); If we use array_pop(), we can get a one-dimensional array, array_pop() Originally deletes and returns the last element of the array.
So we can change the $arr of the appeal into array('a'=>'abc','b'=>'bcd','c'=>'cde'), so that the two The dimensional array becomes a one-dimensional array, but only if the two-dimensional array is a one-dimensional array. If there are multiple one-dimensional arrays, the last array will be returned.
The above has introduced how to turn a simple two-dimensional array into a one-dimensional array, including all aspects. I hope it will be helpful to friends who are interested in PHP tutorials.