fork download
  1. <?php
  2.  
  3. $records = [
  4. 0 => [
  5. 'first_name' => 'abc',
  6. 'last_name' => 'cba',
  7. 'age' => '1'
  8. ],
  9. 1 => [
  10. 'first_name' => 'def',
  11. 'last_name' => 'fed',
  12. 'age' => '2'
  13. ],
  14. 2 => [
  15. 'first_name' => 'ghi',
  16. 'last_name' => 'ihg',
  17. 'age' => '3'
  18. ]
  19. ];
  20.  
  21. // Using the $records array from Example #1
  22. //$firstNames = array_column($records, 'first_name', 'first_name');
  23. $firstNames = array_column($records, 'first_name');
  24.  
  25. var_dump(json_encode($firstNames));
Success #stdin #stdout 0.02s 25400KB
stdin
Standard input is empty
stdout
string(19) "["abc","def","ghi"]"