user3034899
user3034899

Reputation: 83

If isset array - how in php?


I use tmdb_v3.php api with this code:

$movietrailer = $tmdb_V3->movieTrailer($idMovie);

In "pre" query I got this:

Array
(
    [id] => 49017
    [quicktime] => Array
        (
        )

    [youtube] => Array
        (
        )

)

I need an [php iffset]. If [youtube] contain value, echo "We have trailer". If no, echo "No trailer yet :(". I tried this but don't working:

if(isset($movietrailer['youtube']))
{ echo "We have trailer"; } else { echo "No trailer yet :("; }

Upvotes: 0

Views: 1154

Answers (1)

John Conde
John Conde

Reputation: 219804

That value is always set. It just doesn't always have a value. Use empty() see if it has a value:

if(!empty($movietrailer['youtube'])) { 
    echo "We have trailer"; 
} else { 
    echo "No trailer yet :("; 
}

Upvotes: 1

Related Questions