|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-02-27 00:11 UTC] rbro at hotmail dot com
 Description:
------------
Doing the following SimpleXML text comparison does not give the expected results.
Reproduce code:
---------------
<?php
$sxe = simplexml_load_string('<root a="123" />');
echo $sxe['a']."\n";
if ($sxe['a'] == '123')
{
	echo 'They are equal.'."\n";
}
else
{
	echo 'They are not equal.'."\n";
}
?>
Expected result:
----------------
123
They are equal.
Actual result:
--------------
123
They are not equal.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 13:00:01 2025 UTC | 
Yes, doing 'var_dump($sxe['a']);' gives: object(simplexml_element)#2 (1) { [0]=> string(3) "123" } But then changing my if line to: if ($sxe['a'][0] == '123') doesn't work either. How does one then compare an attribute to another value? The documentation at http://docs.php.net/en/ref.simplexml.html states that my original if statement should work (the example under 'Using attributes'). That example doesn't work locally either because of the same issue on the switch statement used.