tags:

views:

216

answers:

3

There are two arrays, that are given for $link from foreach. One time $link must be a first arrow, and a third - 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 - first one has [sizes].

Searching for a way to detect, is there [sizes] in given array.

Tryed if (in_array("[sizes]", $link)) { } else { }, but it doesnt work.

Thanks.

+2  A: 
if (isset($theArray['sizes'])) {...}
chris
$theArray = $link?
Happy
+5  A: 

Since sizes is an array key you can make use of the function array_key_exists which returns TRUE if the given key is set in the array.

if(array_key_exists('sizes',$link)) {
  // sizes exists
}else{
  // sizes does not exist.
}
codaddict
You spell your functions differently than mine...
seanmonstar
@seanmonstar: Thanks for pointing :)
codaddict
doesn't work. Breaks all the code under if(array_key_exisits('sizes',$link)) {
Happy
@Glister: You have a typo in the function name. It should be **array_key_exists** . Here is a **working example** : http://www.ideone.com/jH9OZ
codaddict
thanks, will hold in a mind
Happy
+1  A: 
if(isset($link['sizes'])) {

}

Is this what you're looking for?

Daniel Bingham
yes. This works perfectly, thanks.
Happy