Zend
200-710 · Question #163
Consider the following XML code: ``xml <?xml version="1.0" encoding="utf-8"?> <books> <book id="1">PHP 5.5 in 42 Hours</book> <book id="2">Learning PHP 5.5 The Hard Way</book> </books> `` Which of…
The correct answer is C. echo $xml->book[1]; E. echo $c = $xml->children(); echo $c[1]. See the full explanation below for the reasoning.
XML & Web Services
Question
Consider the following XML code:
<?xml version="1.0" encoding="utf-8"?>
<books>
<book id="1">PHP 5.5 in 42 Hours</book>
<book id="2">Learning PHP 5.5 The Hard Way</book>
</books>
Which of the following SimpleXML calls prints the name of the second book? (Let $xml = simplexml_load_file("books.xml"); ) (Choose 2)Options
- Aecho $xml->books->book[2];
- Becho $xml->books->book[1];
- Cecho $xml->book[1];
- Decho $xml->xpath("/books/book[@id=2]");
- Eecho $c = $xml->children(); echo $c[1];
How the community answered
(28 responses)- A4% (1)
- B11% (3)
- C79% (22)
- D7% (2)
Topics
#SimpleXML#array indexing#XPath#XML navigation
Community Discussion
No community discussion yet for this question.