Add ternary operator to the array output by the template to judge, array operator_PHP tutorial

WBOY
Release: 2016-07-13 10:21:08
Original
1056 people have browsed it

Add ternary operator to the array output by the template for judgment. Array operator

provides a useful judgment method. Add ternary operation to the array output by the template. It is very convenient to judge by using the talisman. Of course you can also use Ajax~

<span><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>无标题</title>
</head>
<body><span>
我的口号是什么?&mdash;&mdash;</span>><{<span>$data</span>['user']?'没有问题':Wow搞大了}> <br/>    //提醒:三元运算符不能接受符号,不然会报错!
                   <{<span>$data</span>['email']}> <br/>
                   <{<span>$data</span>['address']}><br/>
                   <{<span>$data</span>['num']+10}><br/>
</body>
</html></span>
Copy after login

Controller methods

<span><?php</span><br /><span>namespace Home\Controller;</span><br /><span>use Think\Controller;</span><br /><span> <span>public</span> <span>function</span><span> index(){

      </span><span>$data</span>['user']='我爱的是你爱我'<span>;
      </span><span>$data</span>['email']='integer@gmail.cn'<span>;
      </span><span>$data</span>['address']='中国大陆'<span>;
      </span><span>$data</span>['num']='21'<span>;
      </span><span>//</span><span>$this->assign('num',10);</span>
      <span>$this</span>->assign('data',<span>$data</span><span>);
      </span><span>$this</span>-><span>display();
    }</span></span>
Copy after login

Those three ternary operators in C# are probably conditional. How do they operate?

Ternary operator? :
For example: i= 2 > 3 ? 0 : 1
2 is greater than 3, if so, get i = 0; otherwise i=1.

The ternary operator in C# is () A== B?: C!= D<>

Choose B
Ternary operator?:;, which is a relational operator.
is often used for relational comparison, mainly for There are only two states of the comparison relationship (greater than and not greater than, true and false)
First find the value of expression 1, if it is true, then execute expression 2 and return the result of expression 2; if the expression If the value of Formula 1 is false, then Expression 3 will be executed and the result of Expression 3 will be returned
. For example, the following expression:
a>0? a++: (a = 1)
When a>0 is When true, a++ is executed, and the value of the entire expression is equal to the value of expression a++.
When a>0 is false, a=1 is executed, and the value of the entire expression is equal to the value of expression a=1.
Reference: zhidao.baidu.com/question/341063017.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/860924.htmlTechArticleThe ternary operator is added to the array output by the template for judgment. The array operator provides a useful judgment method. , it is very convenient to add the ternary operator to the array output by the template to judge. ...
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