isset not working with multidimensional arrays ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ariskaar
Forum Newbie
Posts: 1
Joined: Wed Jun 17, 2009 8:07 am

isset not working with multidimensional arrays ?

Post by ariskaar »

Look at the following code snippet. Can anyone tell me why the first isset test fails ?

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>
 
The output is as follows:
  • 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...
The XML file that is loaded looks like this:

<?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>
Post Reply