if if true条件检查PHP

时间:2015-09-12 17:52:25

标签: php json if-statement

我想简单地检查json文件在开始时是否包含最新而不应该执行某些功能,如果json文件在开始时包含视频而不是它应该做一些其他的功能。 这是我的PHP代码---

$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

我也是这样试过----

$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

这对我不起作用,任何人都可以帮我解决这个问题。 任何建议都会非常感谢,谢谢先进。

1 个答案:

答案 0 :(得分:2)

使用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