Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active November 11, 2015 20:36
Show Gist options
  • Save kjbrum/552e93a6e9a3f90dd6b0 to your computer and use it in GitHub Desktop.
Save kjbrum/552e93a6e9a3f90dd6b0 to your computer and use it in GitHub Desktop.
Convert an object to an array.
<?php
/**
* Convert an object to an array.
*
* @param array $object The object to convert
* @return array The converted array
*/
function object_to_array( $object ) {
if( !is_object( $object ) && !is_array( $object ) ) return $object;
return array_map( 'object_to_array', (array) $object );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment