|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-02-17 03:50 UTC] marcels at korton dot nl
Description:
------------
When I use the count function to get the number of elements in an array it returns 1. It does this only when I use simpleXML. In version 5.0.0b3 it worked fine.
My example use a book in the xml format. Here is a small part of it
<bookbody>
<part>
<chapter>
<chapheader>
<chapnum>I</chapnum>
<title>The Period</title>
</chapheader>
</chapter>
<chapter>
<chapheader>
<chapnum>II</chapnum>
<title>The Mail</title>
</chapheader>
This continues for al the chapters within the book.
both part and chapter are array's.
We are using the windows precompiled binaries with Sambar server V6.0 build 11 november 2003
Reproduce code:
---------------
$xml_mem = simplexml_load_file('2city11.xml');
for ($i = 0; $i < count($xml_mem->book->bookbody->part); $i++) {
for ($j = 0; $j < count($xml_mem->book->bookbody->part[$i]->chapter); $j++) {
echo $xml_mem->book->bookbody->part[$i]->chapter[$j]->chapheader->title,'<br>';
}
}
Expected result:
----------------
The Period
The Mail
The Night Shadows
The Preparation
The Wine-shop
The Shoemaker
Five Years Later
A Sight
A Disappointment
...
Actual result:
--------------
The Period
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
Arrays are no longer returned. The objects implement iterators so use foreach, ie: foreach ($xml_mem->book->bookbody->part as $part) { foreach($part->chapter as $chapter) { echo $chapter->chapheader->title.'<br>'; } }