-1

How can check if $xml has child "students"?

I'm using SimpleXML to use Xml in php:

$xml = simplexml_load_file('log.xml');

Thanks in advance.

atomikpanda
  • 1,845
  • 5
  • 33
  • 47
  • This is marked as a dupe, but the chosen answer to the linked question is wrong. The answer selected below is correct, and is identical to the highest voted answer on the linked question. – Matt Nov 19 '13 at 19:24

2 Answers2

4

You can use a simple isset() call for that

$node = new SimpleXMLElement('<foo><students>test</students></foo>');

var_dump(isset($node->students));

bool(true)

tlenss
  • 2,609
  • 2
  • 22
  • 26
1
if( isset($xml->students) )
   // Do
Arthur
  • 3,717
  • 7
  • 28
  • 44