array_column() To Hash

no-email (Damien Seguy), Damien Seguy
Sun, 03 Nov 2024 00:00:00 +0000

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 reciproque function for this: turn a hash into an array of arrays or objects.