Created
December 29, 2017 03:21
-
-
Save qutek/e7ac01669bd7ccc18c44b58828014aaf to your computer and use it in GitHub Desktop.
[PHP Convert multidimensional object to array] #php #array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert object to array | |
* @param [type] $obj [description] | |
* @return [type] [description] | |
*/ | |
function obj_to_array($obj) { | |
if(!is_array($obj) && !is_object($obj)) | |
return $obj; | |
if(is_object($obj)) | |
$obj = get_object_vars($obj); | |
return array_map(__FUNCTION__, $obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment