相关疑难解决方法(0)

Reference — What does this symbol mean in PHP?

What is this?

This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.

Why is this?

It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …

php arguments symbols operators

4314
推荐指数
21
解决办法
63万
查看次数

PHP中的?:运算符('Elvis运算符')

我今天在一些PHP代码中看到了这个:

$items = $items ?: $this->_handle->result('next', $this->_result, $this);
Run Code Online (Sandbox Code Playgroud)

我不熟悉?:这里使用的运算符.它看起来像一个三元运算符,但是省略了判断谓词是否为真的表达式.这是什么意思?

php coding-style language-construct conditional-operator

240
推荐指数
5
解决办法
11万
查看次数

什么是?:在PHP 5.3中?

可能重复: 什么是PHP运算符"?"和":"被调用,它们做了什么?

来自http://twitto.org/

<?PHP
    require __DIR__.'/c.php';
    if (!is_callable($c = @$_GET['c'] ?: function() { echo 'Woah!'; }))
        throw new Exception('Error');
    $c();
?>
Run Code Online (Sandbox Code Playgroud)

Twitto使用从PHP 5.3开始提供的几个新功能:

  1. DIR不变
  2. 运营商
  3. 匿名功能

  1. 在PHP 5.3 中,数字2对?:做什么?

  2. 另外,匿名函数是什么意思?那不是已经存在了一段时间的东西吗?

php ternary-operator language-construct conditional-operator php-5.3

83
推荐指数
3
解决办法
4万
查看次数

44
推荐指数
5
解决办法
1万
查看次数

什么 ......:......呢?

$items = (isset($_POST['items'])) ? $_POST['items'] : array();
Run Code Online (Sandbox Code Playgroud)

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

这些代码组合到底做了什么?

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

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

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

php syntax ternary-operator

18
推荐指数
2
解决办法
2万
查看次数

我在哪里可以阅读用"?"完成的条件.和":"(冒号)?

可能重复:
参考 - 这个符号在PHP中意味着什么?

我一直在用if/else或者一年左右做条件.看一些新代码,我看到一个似乎使用的条件?:不是if和else.我想了解更多有关此内容的信息,但我不知道该如何找到解释其工作原理的文章.我该怎么做?

php syntax conditional ternary-operator

0
推荐指数
1
解决办法
1536
查看次数