fork download
  1. <?php
  2.  
  3. function makeProduct($productName) {
  4. return [
  5. 'name' => $productName
  6. ];
  7. }
  8.  
  9. $products = [
  10. makeProduct('hello'),
  11. makeProduct('darkness'),
  12. makeProduct('my'),
  13. makeProduct('old'),
  14. makeProduct('friend')
  15. ];
  16.  
  17. var_dump(array_column($products, 'name'));
  18.  
  19. usort($products, function($a, $b) {
  20. return strcmp($a['name'], $b['name']);
  21. });
  22.  
  23. var_dump(array_column($products, 'name'));
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout
array(5) {
  [0]=>
  string(5) "hello"
  [1]=>
  string(8) "darkness"
  [2]=>
  string(2) "my"
  [3]=>
  string(3) "old"
  [4]=>
  string(6) "friend"
}
array(5) {
  [0]=>
  string(8) "darkness"
  [1]=>
  string(6) "friend"
  [2]=>
  string(5) "hello"
  [3]=>
  string(2) "my"
  [4]=>
  string(3) "old"
}