Re: Object Array?

From: Date: Thu, 18 May 2006 19:55:41 +0000
Subject: Re: Object Array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-236430@lists.php.net to get a copy of this message
Jay Paulson wrote:
don't bother trying to print_r() or var_dump() SimpleXML objects you'll fry your brain - seriously you'll never get anything that makes sense - this is due to the way simpleXML using iterators or something like that - it's a bit like voodoo to me too so I find it hard to explain. I'm sure there is a saying about 'when things are so simple, you just don't get' that's applicable here :-P
KISS - Keep It Simple Stupid. Haha..
Jay Paulson wrote:
I tried with no success yesterday to get an answer to this question so I'll try again. I have an object from using simpleXML and inside that object is an array holding even more objects. However, it's not acting like an array and therefore I can't go through it. (i.e. I can't use the count function to see how big it is and loop through it)
use foreach on it (I think 'it' is a weirdo object that implements an iterator interface - which pretty much sums up simpleXML ;-): foreach ($xml->RES->R as $r) { echo $r->U, $r->UD; // etc } does that get you anywhere?
what happens when you do: foreach ($xml->RES->R as $key => $r) { echo $r->__toString(); // or echo $key; } ?
I've tried that and $xml->RES->R only goes through one record $xml->RES->R[0] and then it stops. What I did find that worked was this.
in what way does it stop?
$i = 0; while (isset($xml->RES->R[$i]) || !empty($xml->RES->R[$i]) {
    // do stuff
    $i++;
}
odd. I don't suppose $xml->RES->R has any methods does it? like hasChildren() or hasAttributes()?

« previous php.general (#236430) next »