Re: Object Array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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()?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux