0

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?

fightstarr20
  • 10,259
  • 33
  • 132
  • 247

1 Answers1

2

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

...
if (array_key_exists("image_id", $myarray[0]))
RomanPerekhrest
  • 75,918
  • 4
  • 51
  • 91