什么事... : ... 做? [英] What does ? ... : ... do?

查看:63
本文介绍了什么事... : ... 做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$items = (isset($_POST['items'])) ? $_POST['items'] : array();

我不明白此代码"? $_POST['items'] : array();"的最后一个片段

I don't understand the last snippet of this code "? $_POST['items'] : array();"

这种代码组合到底能做什么?

What does that combination of code do exactly?

我使用它从html文本框中获取一堆值,并将其存储到会话数组中.但是问题是,如果我尝试重新提交文本框中的数据,则新的数组会话将完全覆盖旧会话数组的空白和全部.

I use it to take in a bunch of values from html text boxes and store it into a session array. But the problem is, if I attempt to resubmit the data in text boxes the new array session overwrites the old session array completely blank spaces and all.

我只想覆盖数组中已经有值的位置.如果用户决定仅填写几个文本框,那么我不希望以前的会话数组数据被空白(从空白文本框)覆盖.

I only want to overwrite places in the array that already have values. If the user decides to fill out only a few text boxes I don't want the previous session array data to be overwritten by blank spaces (from the blank text boxes).

我在想上面的代码是问题所在,但是我不确定它是如何工作的.请赐教.

I'm thinking the above code is the problem, but I'm not sure how it works. Enlighten me please.

推荐答案

这是 a 三元运算符:

如果expr1计算为TRUE,则表达式(expr1) ? (expr2) : (expr3)计算为expr2;如果expr1计算为FALSE,则expr3.

The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.

这篇关于什么事... : ... 做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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