array_column
PHP 5 >= 5.5.0, PHP 7, PHP 8
array_column - Return the values from a single column in the input array
Example #1 Get the column of first names from a recordset
Result: Array
(
[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
)
Example #2 Get the column of last names from a recordset, indexed by the "id" column
Result: Array
(
[2135] => Doe
[3245] => Smith
[5342] => Jones
[5623] => Doe
)
Example #3 Get the column of usernames from the public "username" property of an
object
Result: Array
(
[0] => user 1
[1] => user 2
[2] => user 3
)
Example #4 Get the column of names from the private "name" property of an object
using the magic __get method.
Result: Array
(
[0] => Fred
[1] => Jane
[2] => John
)