array_column   PHP


Summary

Return the values from a single column in the input array


array_column ( array $input , mixed $column_key [, mixed $index_key = NULL ] ) : array

<?php
$arr = [
  ['name' => 'A', 'age' => 10],
  ['name' => 'B', 'age' => 20],
  ['name' => 'C', 'age' => 30],
];
$result = array_column($arr, 'name');
print_r($result);
?>


Result

Array ( [0] => A [1] => B [2] => C )

References


Tags

#array  #array_column 


[ Edit (Author only) ]