$file=isset($file) && $file?$file:'index'这段代码什么意思?

WBOY
Release: 2016-06-23 14:01:33
Original
1074 people have browsed it

$file=isset($file) && $file?$file:'index';
上面代码什么意思?最好能举个例子,上面实际执行了什么?


回复讨论(解决方案)

判断是否存在$file变量,如果存在则取值为$file 如果不存在则为index

? : 三目运算符
等价于
if(isset($file) && $file){
   $file=$file;
}else{
   $file='index';
}

? : 三元运算符 (?)问号前面是判断条件 如果条件为真则取:(冒号)前面的值 如果判断条件为假则取:(冒号)后面的值

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template