phparray-key-exists

PHP array_key_exists not working


I have a PHP array that looks like this if I print_r($myarray)

Array ( [0] => Array ( [description] => testdecr [link] => testlink [image_id] => 150 ) )

I am trying to check for a key called image_id by doing this...

if (array_key_exists("image_id",$myarray)) {
        echo 'Image_id exists';
    }

This is not working, anyone any ideas what I am doing wrong?


Solution

  • "image_id" key is on nested array under position 0.
    It should be:

    ...
    if (array_key_exists("image_id", $myarray[0]))