array_column() To Hash

<?php

class X {
    function foo() {
        print __METHOD__.PHP_EOL;
        print __CLASS__.PHP_EOL;
        print __FUNCTION__.PHP_EOL;
    }
}

(new x)->foo();

    function foo() {
        print __METHOD__.PHP_EOL;
        print __CLASS__.PHP_EOL;
        print __FUNCTION__.PHP_EOL;
    }

foo();

array_column() is a very handy PHP native function, which extracts a index from a list of arrays, or a public property from a list of objects.

The third argument of array_column() is a key, which will be used to reference the value in the resulting array. It is very convenient to turn an array into a hash.

Note that duplicate keys will be overwritten.

Also, there is no reciprocal function for this: turn a hash into an array of arrays or objects.

See Also

PHP Features

Last updated: 14 July 2026