Skip to content

Instantly share code, notes, and snippets.

@dusta
Last active April 8, 2017 08:39
Show Gist options
  • Save dusta/1b070dc17ff2f163eb734b1dbdbfe6d3 to your computer and use it in GitHub Desktop.
Save dusta/1b070dc17ff2f163eb734b1dbdbfe6d3 to your computer and use it in GitHub Desktop.
Function Convert object to array
<?php
/**
* Convert object to array
*/
function objectToArray($obj) {
if(is_object($obj))
$obj = (array) $obj;
if(is_array($obj)) {
$new = array();
foreach($obj as $key => $val) {
$key2 = str_replace("\0", "", $key);
$new[$key2] = object_to_array($val);
}
}else
$new = $obj;
return $new;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment