Home >php教程 >php手册 >PHP入门教程:?(问号)和:(冒号)

PHP入门教程:?(问号)和:(冒号)

WBOY
WBOYOriginal
2016-06-21 08:56:292477browse

例如:

1
 $shenhe=$val['available']?"已审核":"未审核"

经常有刚接触php的朋友问我,php中经常见到如上代码的语句,问号和冒号是什么意思,这个语句是什么意思?

其实,这就是一个if语句的缩写,C语言里的语法,条件表达式e1?e2:e3,若e1为真(非0),则此表达式的值为e2的值;若为假,则表达式的值为e3。等同于

1
2
3
4
5
6
$e="";02.if(e1){
	$e=e2;
}
else{
	$e=e3;
}

其中e1、e2、e3都是表达式。



Statement:
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