Detecting extended_entities for all tweets search in php



I need to get all the images of the tweets in the search, however when using isset to determine if extended_entities exists it converts my array to a string. How could I effectively detect that extended_entities exists? . Here is my code:

foreach ($tweets  as $key => $tweet) {
			if (isset($tweet->extended_entities->media)) {				
				foreach ($tweet->extended_entities->media as $key => $media) {
					if ($media->type=="photo") {
							"media_w"  =>$media->sizes->small->w,
							"media_h"  =>$media->sizes->small->h);
				$image="no image";


This is not really related to the Twitter API itself but sounds like a PHP problem, you might want to ask on Stackoverflow, if you get no answer here.