note 77717 added to function.get-object-vars
| From: | firemouth at gmail dot com | Date: | Mon, 10 Sep 2007 13:48:48 +0000 |
| Subject: | note 77717 added to function.get-object-vars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130340@lists.php.net to get a copy of this message | ||
This is a slight modification of the previous poster's function. We ran into a problem using
this function when we had a JS array nested inside a JS hash.
Something like this...
myHash = new Hash();
myHash[address] = new Array();
When we threw that at this function, it found the first hash as an object, and then using the
previous poster's function, it did not consider the array as an "object." Instead it
gave us a std_object type and we were unable to make any use of it.
The modification we made was adding a check for is_array inside both the is_object and is_array
checks when you call the function. This checks for an array inside either an object or a nested
array.
function conv_obj($Data){
if(is_object($Data)){
foreach(get_object_vars($Data) as $key=>$val){
if(is_object($val) || is_array($val)){
$ret[$key]=conv_obj($val);
}else{
$ret[$key]=$val;
}
}
return $ret;
}elseif(is_array($Data)){
foreach($Data as $key=>$val){
if(is_object($val) || is_array($val)){
$ret[$key]=conv_obj($val);
}else{
$ret[$key]=$val;
}
}
return $ret;
}else{
return $Data;
}
}
----
Server IP: 209.41.74.194
Probable Submitter: 207.252.175.162
----
Manual Page -- http://www.php.net/manual/en/function.get-object-vars.php
Edit -- https://master.php.net/note/edit/77717
Del: integrated -- https://master.php.net/note/delete/77717/integrated
Del: useless -- https://master.php.net/note/delete/77717/useless
Del: bad code -- https://master.php.net/note/delete/77717/bad+code
Del: spam -- https://master.php.net/note/delete/77717/spam
Del: non-english -- https://master.php.net/note/delete/77717/non-english
Del: in docs -- https://master.php.net/note/delete/77717/in+docs
Del: other reasons-- https://master.php.net/note/delete/77717
Reject -- https://master.php.net/note/reject/77717
Search -- https://master.php.net/manage/user-notes.php