If array exists (php)

There are two arrays that are specified for $link

from foreach

. Once there $link

should be the first arrow, and the third should be the second. So:

1 array:

Array (

[width] => 800

[height] => 1142

[hwstring_small] => height='96' width='67' [file] => 2010/04/white-1051279.jpg

[sizes] => Array (
[thumbnail] => Array ( [file] => white-1051279-100x150.jpg [width] => 100 [height] => 150 )
[medium] => Array ( [file] => white-1051279-200x285.jpg [width] => 200 [height] => 285 )
)

[image_meta] => Array ( [aperture] => 0 [credit] => [camera] => [caption] => [created_timestamp] => 0

[copyright] => [focal_length] => 0 [iso] => 0 [shutter_speed] => 0 [title] => ) ) 

      

2 array:

Array (

[width] => 50 [height] => 50 [hwstring_small] => height='50' width='50' [file] => 2010/04/images1.jpeg

[image_meta] => Array ( [aperture] => 0 [credit] => [camera] => [caption] => [created_timestamp] => 0

[copyright] => [focal_length] => 0 [iso] => 0 [shutter_speed] => 0 [title] => )
)

      

The difference is the first has [sizes]

.

Search for a detection method, is [sizes]

in the given array
.

Tried if (in_array("[sizes]", $link)) { } else { }

it but it doesn't work.

Thanks.

+2


a source to share


3 answers


if(isset($link['sizes'])) {

}

      



Is this what you are looking for?

+3


a source


Since sizes

is the key of an array, you can use the array_key_exists function , which returns TRUE

if the given key

is set to array

.



if(array_key_exists('sizes',$link)) {
  // sizes exists
}else{
  // sizes does not exist.
}

      

+6


a source


if (isset($theArray['sizes'])) {...}

      

+3


a source







All Articles