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

WBOY
Release: 2016-06-13 11:50:04
Original
1172 people have browsed it

$file=isset($file) && $file?$file:'index'这段代码什么意思?
$file=isset($file) && $file?$file:'index';
上面代码什么意思?最好能举个例子,上面实际执行了什么?
------解决方案--------------------
判断是否存在$file变量,如果存在则取值为$file 如果不存在则为index
------解决方案--------------------
? : 三目运算符
等价于
if(isset($file) && $file){
   $file=$file;
}else{
   $file='index';
}
------解决方案--------------------
? : 三元运算符 (?)问号前面是判断条件 如果条件为真则取:(冒号)前面的值 如果判断条件为假则取:(冒号)后面的值

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!