简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM