我应该在这里做什么?



=& 参考

参考任务操作员在PHP, =& 什么意思是“=&”和“&="操作员在PHP? 什么意思是“&=”和“=&”操作员在PHP?

















PHP 中的奇怪打印行为?



= 任命运营商

三种不同的平等


如何区分PHP平等(==双等)和身份(===三等)比较操作员?PHP!=和 ==操作员3个不同的平等类型和(严格)较大的/较小的比较在PHP


=== 比较运营商






比特币运营商


上一篇: 逻辑运营商












[ ] Arrays (自 PHP 5.4 以来简短的合成)


PHP 短标签是否可用?


二角形字符范围




# One-line shell 风格评论


NullSafe Operator 通话(自 PHP 8.0 以来)

PHP 中有“零安全操作员”吗?



当前回答

_ Alias for gettext( )

作为 _() 的字符“_”是 gettext() 函数的标志。

其他回答

问答:

什么是“”意思?


答案:

编制:

要了解这一点,我们必须知道什么是协同序列,当一个常规程序员认为一个序列时出现的第一件事(在PHP中)会是类似于:

$myArray1 = array(2016, "hello", 33);//option 1

$myArray2 = [2016, "hello", 33];//option 2

$myArray3 = [];//option 3
$myArray3[] = 2016; 
$myArray3[] = "hello"; 
$myArray3[] = 33;

在哪里,如果我们想在代码的某些后续部分召唤序列,我们可以:

echo $myArray1[1];// output: hello
echo $myArray2[1];// output: hello
echo $myArray3[1];// output: hello

差异(序列和附属序列之间):

在附属序列的声明中,您不只是将您想要插入序列的值,但您还将所需的指数值(称为密钥)插入,当您在代码的后部分召唤序列时使用。

例如:

$myArray1 = array( 
    "Year" => 2016, 
    "Greetings" => "hello", 
    "Integer_value" => 33);//option 1

$myArray2 = [ 
    "Year" =>  2016, 
    "Greetings" => "hello", 
    "Integer_value" => 33];//option 2

$myArray3 = [];//option 3
$myArray3["Year"] = 2016; 
$myArray3["Greetings"] = "hello"; 
$myArray3["Integer_value"] = 33;

现在,以获得与以前相同的产量,关键值将用于雷索指数:

echo $myArray1["Greetings"];// output: hello
echo $myArray2["Greetings"];// output: hello
echo $myArray3["Greetings"];// output: hello

在 PHP 8 中

而不是写经典!== null 你可以使用操作员写一行代码,代码变得相当清晰:

之前:

$firsName =  null;
if ($session !== null) {
    $user = $session->user;
    if ($user !== null) {
        $name = $user->getName();
        if ($name !== null) {
            $firstName = $name->firstName;
        }
    }
}

之后:

$firsName = $session?->user?->getName()?->firstName;

使用对比而不是交换. 对比表达使用严格的比较(===) 相反. 对比是严格的,无论严格的类型。

之前:

switch ('A') {
    case 'A':
        echo "found A";
        break;
    case 'B':
        echo "found B";
        break;
}
// Result: "found A"

之后:

echo match ('A') {
  'A' => "found A",
  'B' => "found B",
};
// Result: "found A"

Null Coalesce 操作器 “??” (在 PHP 7 中添加)

不是一个运营商最受欢迎的名称,但PHP 7带来了相当方便的零冷却,所以我认为我会分享一个例子。

在PHP 5中,我们已经有一个特纳操作器,测试一个值,然后返回第二个元素,如果它返回真实,第三个元素,如果它没有:

echo $count ? $count : 10; // outputs 10

在PHP 7中,我们还获得了操作员,而不是指示极端的混乱,这就是我通常会使用两个问题标志相结合的方式,而不是允许我们连接一行值。

// $a is not set
$b = 16;

echo $a ?? 2; // outputs 2
echo $a ?? $b ?? 7; // outputs 16

这个结构是有用的,以优先考虑一个或多个值来自用户输入或现有配置,并安全地落后于一个特定的默认设置,如果该配置缺乏。

增加 / 减少运营商

+ 增强运营商

排斥运营商

Example    Name              Effect
---------------------------------------------------------------------
++$a       Pre-increment     Increments $a by one, then returns $a.
$a++       Post-increment    Returns $a, then increments $a by one.
--$a       Pre-decrement     Decrements $a by one, then returns $a.
$a--       Post-decrement    Returns $a, then decrements $a by one.

它可以在变量之前或之后进行。

例如:

$apples = 10;
for ($i = 0; $i < 10; ++$i) {
    echo 'I have ' . $apples-- . " apples. I just ate one.\n";
}

活例子

在上述情况下 ++$i 使用,因为它更快。

预增略略快一点,因为它真的增加了变量,然后“返回”结果,后增略创造了一个特殊变量,复制了第一个变量的值,只有在第一个变量被使用后,它将其值取代为第二个。

但是,你必须使用 $ 苹果 - 因为首先,你想显示目前的苹果数量,然后你想从它中提取一个。

$i = "a";
while ($i < "c") {
    echo $i++;
}

一旦 z 到达 aa 是下一个,等等。

请注意,字符变量可以增加,但不能减少,即使如此,只有平坦的 ASCII 字符(a-z 和 A-Z)得到支持。


Stack Overflow 文章:

理解增加

Syntax Name Description
x == y Equality true if x and y have the same key/value pairs
x != y Inequality true if x is not equal to y
x === y Identity true if x and y have the same key/value pairs
in the same order and of the same types
x !== y Non-identity true if x is not identical to y
x <=> y Spaceship 0 if x is equal to y, greater than 0 if x > y, less than 0 if x < y
++x Pre-increment Increments x by one, then returns x
x++ Post-increment Returns x, then increments x by one
--x Pre-decrement Decrements x by one, then returns x
x-- Post-decrement Returns x, then decrements x by one
x and y And true if both x and y are true. If x=6, y=3 then
(x < 10 and y > 1) returns true
x && y And true if both x and y are true. If x=6, y=3 then
(x < 10 && y > 1) returns true
x or y Or true if any of x or y are true. If x=6, y=3 then
(x < 10 or y > 10) returns true
x || y Or true if any of x or y are true. If x=6, y=3 then
(x < 3 || y > 1) returns true
a . b Concatenation Concatenate two strings: "Hi" . "Ha"