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

Use array_column:

$result = array_column($array, 0);

foreach ($main_array as $inner_array){
  echo $inner_array[0] . "\n";
}

Supposing you use php 5.3:

$first_elements = array_map(function($i) {
    return $i[0];
}, $data);

Otherwise you need to implement a callback function or just use plain old foreach


Here is a one-liner:

array_map('array_shift', $array);

Will return:

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

And here is another one:

array_combine(array_map('array_shift', $temp), array_map('array_pop', $temp))

Will return:

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