fork download
  1. <?php
  2. // Tableau représentant un jeu d'enregistrements issu d'une base de données
  3.  
  4. $records = array (
  5. 0 =>
  6. 'id' => '3',
  7. 'groupname' => 'test',
  8. 'cinema_group' => '2',
  9. 'cinema_name' => 'test_1',
  10. 'cinema_location' => 'test_location1',
  11. ),
  12. 1 =>
  13. 'id' => '4',
  14. 'groupname' => 'test',
  15. 'cinema_group' => '2',
  16. 'cinema_name' => 'test_2',
  17. 'cinema_location' => 'test_location2',
  18. ),
  19. 2 =>
  20. 'id' => '5',
  21. 'groupname' => 'test',
  22. 'cinema_group' => '2',
  23. 'cinema_name' => 'test3',
  24. 'cinema_location' => 'test_location3',
  25. ),
  26. 3 =>
  27. 'id' => '6',
  28. 'groupname' => 'test',
  29. 'cinema_group' => '2',
  30. 'cinema_name' => 'test4',
  31. 'cinema_location' => 'test_location4',
  32. ),
  33. );
  34.  
  35. $first_names = array_column($records, null, 'id');
  36.  
  37. print_r($first_names);
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [3] => Array
        (
            [id] => 3
            [groupname] => test
            [cinema_group] => 2
            [cinema_name] => test_1
            [cinema_location] => test_location1
        )

    [4] => Array
        (
            [id] => 4
            [groupname] => test
            [cinema_group] => 2
            [cinema_name] => test_2
            [cinema_location] => test_location2
        )

    [5] => Array
        (
            [id] => 5
            [groupname] => test
            [cinema_group] => 2
            [cinema_name] => test3
            [cinema_location] => test_location3
        )

    [6] => Array
        (
            [id] => 6
            [groupname] => test
            [cinema_group] => 2
            [cinema_name] => test4
            [cinema_location] => test_location4
        )

)