代码":"在PHP中 [英] the code " : " in php

查看:89
本文介绍了代码":"在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想知道php中的语法:"是什么意思,我已经看过几次了,但是我似乎无法自己解释一下.您还可以在句子中使用它吗?...还是我的意思是示例代码?

I'm curious to know what the syntax " : " mean in php I've seen it a couple of times but I can't seem to explain it to myself. Can you also use it in a sentence....or i mean, sample code?

**

对不起,我指的是三元运算符.也感谢其他条目.抱歉,一开始我不知道该怎么称呼.

sorry folks, I was referring to the ternary operator. Thanks for the other entries as well. I didn't know what to call it at first, apologies.

推荐答案

也许您指的是三元运算符,它使用??和:如下:

Perhaps you are referring to the ternary operator, which uses a ? and : as follows:

$variable = boolean_expression ? "true_value" : "false_value";

此代码是if-else的简写:

This code is shorthand for an if-else:

if (boolean_expression) {
   $variable = "true_value";
}
else {
   $variable = "false_value";
}

这篇关于代码":"在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆