search
Homephp教程php手册模板输出的数组中增加三元运算符来判断,数组运算符

模板输出的数组中增加三元运算符来判断,数组运算符

得出一个好用的判断方法,在模板输出的数组中增加三元运算符来判断,挺方便的。当然你也可以用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>

控制器方法

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

 

C# 三元运算符是那三个,估计是条件的,是怎运算的

三元运算符 ?:
例如:i= 2 > 3 ? 0 : 1
2大于3嘛,如果是,就得到i = 0;否则i=1.
 

C#中的三元运算符是() A== B?: C!= D

选B
三目运算符?:; ,属于关系运算符,
常用于关系比较,主要用于比较关系的状态只有两种的情况(大于 和 不大于,真 和 假)
先求表达式1的值, 如果为真, 则执行表达式2,并返回表达式2的结果 ; 如果表达式1的值为假, 则执行表达式3 ,并返回表达式3的结果
比如以下表达式:
a>0? a++:(a = 1)
当a>0为真 时,执行a++,整个表达式的值等于表达式a++的值,
当a>0为假 时,执行a=1,整个表达式的值等于表达式a=1的值。
参考资料:zhidao.baidu.com/question/341063017.html
 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor