三元运算符 php_php –三元运算符

作者:神秘网友 发布时间:2020-10-15 19:13:33

三元运算符 php_php –三元运算符

三元运算符 php_php –三元运算符 三元运算符 php_php –三元运算符

三元运算符 php

We have previously examined the if-elseif-else conditional statements. We know that these statements provide branching ability according to the conditions. While using these statements in single and simple situations it may become a trivial task. Php provides an alternative way for simple usage. This is called ternary operators.

我们之前已经检查过if-elseif-else条件语句。 我们知道这些语句根据条件提供分支能力。 在单一和简单的情况下使用这些语句时,这可能会变得很简单。 PHP提供了另一种简单使用方法。 这称为三元运算符。

句法 (Syntax)

Syntax of ternary operator is like below. Php looks to the CONDITION and if the result is true the TRUE part is executed if not FALSE part code is executed.

三元运算符的语法如下。 Php查找条件,如果结果为true ,则执行TRUE部分;如果未执行FALSE部分代码,则执行TRUE。

(CONDITION ? TRUE : FALSE)

例子 (Examples)

Here we will check the login function status and if the login is successful the function will return true and true part of the ternary operator will be executed.

在这里,我们将检查登录函数的状态,如果登录成功,该函数将返回true并且将执行三元运算符的true部分。

$status = login();

($status ? echo "Successfully logged on" : echo "Login Failed");

好处 (Advantages)

  • The ternary operator will make code simpler

    三元运算符将使代码更简单
  • The ternary operator will make code more readable

    三元运算符将使代码更具可读性
  • The ternary operator will make the code shorter

    三元运算符将使代码更短
LEARN MORE  How To Install Apache 2.4 and PHP 7.3 On Fedora, CentOS, RHEL Linux? 了解更多如何在Fedora,CentOS,RHEL Linux上安装Apache 2.4和PHP 7.3?

翻译自: https://www.poftut.com/php-ternary-operators/

三元运算符 php

三元运算符 php_php –三元运算符相关教程

  1. sql定义布尔类型变量_Php –布尔变量类型,True,False

    sql定义布尔类型变量_Php –布尔变量类型,True,False sql定义布尔类型变量 [rps-include post=6522] [rps-include post = 6522] Programming generally consist of numeric and logic operations. We have seen numeric variables in previous post. Now we

  2. c浮点型变量初始值整数_Php –数值变量类型,例如整数,浮点数,

    c浮点型变量初始值整数_Php –数值变量类型,例如整数,浮点数,双精度 c浮点型变量初始值整数 [rps-include post=6522] [rps-include post = 6522] Php provides different numeric variable types. In this tutorial we will look them in detail. The nume

  3. 数组类型变量传值_Php –数组变量类型

    数组类型变量传值_Php –数组变量类型 数组类型变量传值 [rps-include post=6522] [rps-include post = 6522] We have used single value variable types up to now. But the real world problems may need different solutions and variables then those. We

  4. [网鼎杯 2020 朱雀组]phpweb

    [网鼎杯 2020 朱雀组]phpweb 解题过程如下 进来的页面不对劲,虽然不知道什么梗但是有一说一确实丑,如果注意一下还会发现这个页面在不断刷新,先抓个包看看。 发现这里上传了两个参数,分别是 func 和 p 。 func 猜测是 function , p 应该是 payload (猜的

  5. shell脚本执行exec_如何使用PHP Exec和示例执行Shell命令

    shell脚本执行exec_如何使用PHP Exec和示例执行Shell命令 shell脚本执行exec Php provides web-based functionalities to develop web applications. But it also provides system related scripting and execution features. exec() function is used to exe

  6. ThinkPHP菜单无极分类

    ThinkPHP菜单无极分类 controller控制器代码: /** * 菜单列表 */ public function index(){ $menuList= Db::name('menu')-order('sort,id')-select();//递归排序$menuList= $this-sort($menuList);$this-assign('menuList',$menuList); return view(); }prot

  7. PHP Glob()函数以示例匹配路径,目录,文件名

    PHP Glob()函数以示例匹配路径,目录,文件名 glob is a general term used to define techniques to match specified pattern according to rules related Unix shell. Linux and Unix systems and shells also supports glob and also provide function g

  8. 系统调用exec_Exec系统调用C和PHP教程的示例

    系统调用exec_Exec系统调用C和PHP教程的示例 系统调用exec exec() function is a function used to create and run processes in operating systems Linux, Windows and MacOS. exec() function has different useful variants like execve() , execl() , exe