Home > Software engineering >  Get a value in a php array
Get a value in a php array

Time:10-07

Hi guys in this array:

[7] => Array ( 
    [user] => Array ( 
        [id] => xxxxxx 
        [type] => user 
        [first_name] => xxxxxx 
        [verified] => 
        [restricted] => 
        [status] => Array ( 
            [_] => userStatusOffline 
            [was_online] => 1665123327 
        ) 
        [access_hash] => -xxxxxx 
        [bot_nochats] => 
    ) 
    [date] => xxxxxx 
    [role] => user 
)

i try to get the value :

[status] and [was_online]

i can get the value [id] like this :

$user_ID = $member['user']['id'];

but no way to get [status] or [_] or [was_online]

Thx for the help !


I tried :

$user_status = $member['user']['status']['_'];

$user_status = $member['user']['status']['was_online'];

Result is always : Undefined array key "status"

CodePudding user response:

$was_online = $member['user']['status']['was_online'];

CodePudding user response:

If you have this array :

$member = array( 
    'user' => array ( 
        'id' => 'xxxxxx', 
        'type' => 'user', 
        'first_name' => 'xxxxxx', 
        'verified' => '',
        'restricted' => '',
        'status' => array ( 
            '_' => 'userStatusOffline', 
            'was_online' => '1665123327' 
        ), 
        'access_hash' => '-xxxxxx', 
        'bot_nochats' => ''
    ), 
    'date' => 'xxxxxx', 
    'role' => 'user' 
);

And you use this code

echo "<br />".$member["user"]["id"];
echo "<br />".$member["user"]["status"]["_"];
echo "<br />".$member["user"]["status"]["was_online"];

You have this display

// xxxxxx
// userStatusOffline
// 1665123327
  • Related