Re: Finding value in multi-dimensional array

From: Date: Fri, 09 Apr 2004 20:06:05 +0000
Subject: Re: Finding value in multi-dimensional array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-183029@lists.php.net to get a copy of this message
Verdon Vaillancourt wrote:
Hi, being somewhat of a noob, I hope I'm using the right language to phrase this question... In a project I am working with, I have a multi-dimensional array in session when a user logs in. Visually, it looks something like this... OBJ_user
    username => value
    isAdmin => value
    modSettings =>  contacts => array
                    news => array
                    listings => firstname => value
                                lastname => value
                                active => value
                                phone => value
                    gallery => array
                    anothermod => array
    userID => value
    js => value
I'm trying to check the value of active for an if() statement and can't seem to figure out the correct syntax to get it to work. I've tried if($_SESSION["OBJ_user"]->modSettings["listings"]->active == "1") {
    then do something;
} else {
    then do something else;
} if($_SESSION["OBJ_user"]["modSettings"]["listings"]["active"]) {
    then do something;
} else {
    then do something else;
} if($_SESSION["OBJ_user"]["modSettings"]["listings"]["active"] == "1") {
    then do something;
} else {
    then do something else;
} and none of them work even though I know the session value is there. Any advice as to what I'm doing wrong? Thanks, verdon
The second of your three attempts should work fine, as should the third. Are you certain the actual value of active isn't 0? Try echoing the value of it to the screen, or do a print_r($_SESSION['OBJ_user']) to check the values and structure of the whole multidimensional array. Andy

« previous php.general (#183029) next »