Whenever I wanted to get index an array by the column value I used to do the following

[cc lang=”php”] ‘d604679c’, ‘name’ => ‘Jac Wright’, ’email’ => ‘[email protected]’, ], [ ‘id’ => ‘9d8d42bf’, ‘name’ => ‘Arul Kumaran’, ’email’ => ‘[email protected]’, ], ]; print_r(array_combine(array_column($arr, ‘id’), $arr)); /* //prints the following Array ( [d604679c] => Array ( [id] => d604679c [name] => Jac Wright [email] => [email protected] ) [9d8d42bf] => Array ( [id] => 9d8d42bf [name] => Arul Kumaran [email] => [email protected] ) ) */[/cc]

Because I assumed array column will only extract the values in one column, in fact, it can extract any column as key and any column as the value. See the following example

[cc lang="php"]print_r(array_column($arr, 'name', 'id'));
/* //prints
Array
 (
     [d604679c] => Jac Wright
     [9d8d42bf] => Arul Kumaran
 )
*/[/cc]

going further, we can send null as the second parameter to get the same response as before

[cc lang="php"]print_r(array_column($arr, null, 'id'));
/* //prints the following
Array
(
    [d604679c] => Array
        (
            [id] => d604679c
            [name] => Jac Wright
            [email] => [email protected]
        )

    [9d8d42bf] => Array
        (
            [id] => 9d8d42bf
            [name] => Arul Kumaran
            [email] => [email protected]
        )

)
*/[/cc]