I am using this kind of array
array[
0 => 'top left',
1 => 'top right',
];
array[
0 => 'Switch Up',
1 => 'Switch Down',
];
My desired output should be like
array[
0 => 'top left',
1 => 'Switch Up',
];
array[
0 => 'top right',
1 => 'Switch Down',
];
Some one please help me.
2
Answers
You should write your own function like that:
Here’s an example of the use of array_column():
The output would be:
For a demo see: https://3v4l.org/msjJs
This solution is not self-evident, if you’re unfamiliar with it.
The
$combined
array is 2-dimensional, and looks like this:With
array_column($combined, 0)
you get all the values with the zero keys from the nested arrays. Witharray_column($combined, 1)
you get all values with key = 1.