PHP Print keys from an object?
If the 'object' is actually an associative array rather than a true object then array_keys()
will give you what you need without warnings or errors.
On the other hand, if your object is a true object, then you will get a warning if you try use array_keys()
directly.
You can extract the key-value pairs from an object as an associative array with get_object_vars()
, you can then get the keys from this with array_keys()
:
$keysFromObject = array_keys(get_object_vars($anObject));