note 56691 modified in function.simplexml-load-file by danbrown

From: Date: Thu, 24 Jul 2008 13:32:23 +0000
Subject: note 56691 modified in function.simplexml-load-file by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142656@lists.php.net to get a copy of this message
If the property of an object is empty the array is not created. Here is a version object2array that transfers properly. <?php function object2array($object) { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) $return[$key] = object2array($value); } else { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) $return[$key] = ($key && !$value) ? NULL : object2array($value); } else return $object; } return $return; } ?> --was-- If the property of an object is empty the array is not created. Here is a version object2array that transfers properly. function object2array($object) { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) $return[$key] = object2array($value); } else { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) $return[$key] = ($key && !$value) ? NULL : object2array($value); } else return $object; } return $return; } http://php.net/manual/en/function.simplexml-load-file.php

« previous php.notes (#142656) next »