isset not working with multidimensional arrays ?
Posted: Wed Jun 17, 2009 8:45 am
Look at the following code snippet. Can anyone tell me why the first isset test fails ?
The output is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<logcontrol level="TRACE" logfile="stdlog.log">
<srcfile name="LdaData.php">
<phpfunction name="hentLDA" logfile="hentLDA.log"/>
</srcfile>
<srcfile name="KundeInfo.php" level="TRACE" logfile="database.log"/>
</logcontrol>
Code: Select all
<html><body>
<?php
$logproperties = simplexml_load_file("logproperties.xml");
print_r($logproperties);
if(isset($logproperties['srcfile'])) {
echo "<p>This should work...";
} else {
echo "<p>Why doesn't it work?";
}
if(isset($logproperties['level'])) {
echo "<p>This, however, DOES work...";
}
?>
</body></html>
- SimpleXMLElement Object ( [@attributes] => Array ( [level] => TRACE [logfile] => stdlog.log ) [srcfile] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => LdaData.php ) [phpfunction] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => hentLDA [logfile] => hentLDA.log ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => KundeInfo.php [level] => TRACE [logfile] => database.log ) ) ) )
Why doesn't it work?
This, however, DOES work...
<?xml version="1.0" encoding="UTF-8"?>
<logcontrol level="TRACE" logfile="stdlog.log">
<srcfile name="LdaData.php">
<phpfunction name="hentLDA" logfile="hentLDA.log"/>
</srcfile>
<srcfile name="KundeInfo.php" level="TRACE" logfile="database.log"/>
</logcontrol>