Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Get the first value of all arrays in a multidimensional array [duplicate]

Here's a section my multidimensional array:

Array ( 
[0] => Array ( [0] => Height [1] => 40 ) 
[1] => Array ( [0] => Weight [1] => 15 ) 
[2] => Array ( [0] => Ctr_Percent [1] => 15 ) 
) 

What would the syntax be for just printing height, weight, and ctr_percent? I don't mean echoing it like:

echo $array[0][0];
echo $array[1][0];

Is there a way to iterate through the entire multidimensional array and echo out the first value of each child array?

like image 472
Norse Avatar asked Apr 22 '12 21:04

Norse


1 Answers

Use array_column:

$result = array_column($array, 0);
like image 54
Robo Robok Avatar answered Oct 04 '22 16:10

Robo Robok