W3docs

PHP - Extracting a property from an array of objects

To extract a property from an array of objects in PHP, you can use the array_column function.

To extract a property from an array of objects in PHP, you can use the array_column function. This function returns an array containing all the values of a specific column in the input array.

Here's an example of how you can use array_column:

Example of extracting a property from an array of objects in PHP

php— editable, runs on the server

You can also use a combination of array_map and get_object_vars to extract properties from an array of objects:

Example of extracting properties from an array of objects with "array_map" and "get_object_vars" functions in PHP

php— editable, runs on the server

You can also use a foreach loop to extract the properties from the objects:

Example of extracting properties from an array of objects with a foreach loop in PHP

php— editable, runs on the server