user2620804 user2620804 - 2 months ago 6
PHP Question

Compare single array value

How can I do a comparison when my array returns value with index.

Returned value is Array ( [isMember] => 0 ) and I want do to a comparison on the value only

if ($memberStatus == 0)
{
print_r($memberStatus);
}

Answer

If you have an array like this:

$data = [ 'isMember' => 0, 'data1' => 1, 'data2' => 2 /* ... */ ];

You can access single elements by using the name of the array and write the key in square brackets:

// change isMember to whatever key-value pair you need
$memberStatus = $data['isMember'];

if ($memberStatus === 0)
{
    print 'user is a member';
}

else
{
    print 'user it not a member';
}