Skip to content

Instantly share code, notes, and snippets.

@rolldone
Created June 1, 2019 23:34
Show Gist options
  • Save rolldone/b92e85142fea0c7ba678acc054646ecd to your computer and use it in GitHub Desktop.
Save rolldone/b92e85142fea0c7ba678acc054646ecd to your computer and use it in GitHub Desktop.
public function to_array(&$object = '')
{
// IF OBJECT, MAKE ARRAY
if (is_object($object)) {$object = (array) $object;}
// IF NOT ARRAY OR EMPTY ARRAY, RETURN = LEAVES SCALARS
if (!is_array($object) || empty($object)) {return;}
// FOR EACH ITEM, RECURSE VALUE
foreach ($object as &$Value) {$this->to_array($Value);}
}
/**
---------------------------------------------
How to use ?
------------------ **/
$test = json_decode($stringJSON);
/** Dont new initalize beginning just keep $test to converted **/
to_array($test);
dd($test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment