Istiak Mahmood
Istiak Mahmood

Reputation: 2422

if else true condition to check in PHP

i want a simple simply check if the json file contains latest in the beganing than it should do some function, if the json file contains videos in the beganing than it should do some other functions. This is my PHP code ---

$url = 'http://www.hello.se/3209406a5d0f95&limit=15';
$json = json_decode(file_get_contents($url), true);

if($json['latest']['videos']){ // how can i just put a condition where if it is true than 
//do some function or if it is not true go to the next condition which is else if($json['videos']){ ...

        // do some functions
       }
else if($json['videos']){
// do some functions

i have also tried like so ----

$url = 'http://www.hello.se/3209406a5d0f95&limit=15';
$json = json_decode(file_get_contents($url), true);

if($json['latest']['videos'] === true){

        // do some functions
       }
else if($json['videos'] === true){
// do some functions

which is not working for me, can anyone help me to fix this issue. Any advice will be really appreciate, thanks in advanced.

Upvotes: 1

Views: 487

Answers (1)

Halayem Anis
Halayem Anis

Reputation: 7785

use isset() : http://php.net/manual/en/function.isset.php

if(isset($json['latest']['videos'])){ // how can i just put a condition where if it is true than 
//do some function or if it is not true go to the next condition which is else if($json['videos']){ ...

        // do some functions
       }
else if(isset($json['videos'])){
// do some functions

Upvotes: 2

Related Questions