I've already been mocked on SO for promoting a variadic approach for this kind of question, but I think it is important to show what the clever developers of php have afforded coders to do.
The ...
(splat operator) tells array_map()
that a multi-dimensional (with a potentially variable number of subarrays) array is coming. The function then synchronously iterates each individual subarray.
In the following code, I have commented out a method that statically names the arguments $v1
,$v2
,$v3
used by array_map()
. This will work for the OP's case.
The line of code following the commented one, is a method that dynamically accesses the values without needing to do any variable naming. This will also be hugely flexible for any case where the structure of the multi-dimensional array changes its size/shape.
PHP Manual references:
One-liner (requires PHP5.6+): (Demo with additional examples/considerations)
$m_array=[[5, 4, 10], [11, 13, 15], [32, 14, 15]];
//$new=array_map(function($v1,$v2,$v3){return [$v1,$v2,$v3];},...$m_array);
$new=array_map(function(){return func_get_args();},...$m_array);
var_export($new);
Output:
array (
0 =>
array (
0 => 5,
1 => 11,
2 => 32,
),
1 =>
array (
0 => 4,
1 => 13,
2 => 14,
),
2 =>
array (
0 => 10,
1 => 15,
2 => 15,
),
)