Create object to array after json decode

After taking a few look at json encode, it looks like after I decode with json decode it becomes object, so after json_decode all array becomes obj to overcome this need the function below...


function object_to_array($data)
{
if (is_array($data) || is_object($data))
{
$result = array();
foreach ($data as $key => $value)
{
$result[$key] = object_to_array($value);
}
return $result;
}
return $data;
}

Subscribe to You Live What You Learn

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe