我应该在这里做什么?
=& 参考
参考任务操作员在PHP, =& 什么意思是“=&”和“&="操作员在PHP? 什么意思是“&=”和“=&”操作员在PHP?
PHP 中的奇怪打印行为?
= 任命运营商
三种不同的平等
如何区分PHP平等(==双等)和身份(===三等)比较操作员?PHP!=和 ==操作员3个不同的平等类型和(严格)较大的/较小的比较在PHP
=== 比较运营商
比特币运营商
上一篇: 逻辑运营商
[ ] Arrays (自 PHP 5.4 以来简短的合成)
PHP 短标签是否可用?
二角形字符范围
# One-line shell 风格评论
NullSafe Operator 通话(自 PHP 8.0 以来)
PHP 中有“零安全操作员”吗?
NullSafe 运营商
在 PHP 8.0 中添加
它是 NullSafe 运营商,如果您尝试引用函数或从零中获取值,则返回零。
$objDrive = null;
$drive = $objDrive?->func?->getDriver()?->value; //return null
$drive = $objDrive->func->getDriver()->value; // Error: Trying to get property 'func' of non-object
Nullsafe 运营商不使用序列密钥:
$drive['admin']?->getDriver()?->value //Warning: Trying to access array offset on value of type null
$drive = [];
$drive['admin']?->getAddress()?->value //Warning: Undefined array key "admin"
PHP Strings: PHP Strings 可以用四种方式定义,而不仅仅是两种方式:
(一)单一引用:
$string = 'This is my string'; // print This is my string
二、双重引用:
$str = 'string';
$string = "This is my $str"; // print This is my string
3、继承人:
$string = <<<EOD
This is my string
EOD; // print This is my string
4) Nowdoc (自 PHP 5.3.0 以来):
$string = <<<'END_OF_STRING'
This is my string
END_OF_STRING; // print This is my string
航天运营商 <=> (添加到 PHP 7)
<=> 航天运营商的例子(PHP 7、来源:PHP手册):
Integers, Floats, Strings, Arrays & Objects for 三路比较变量。
// Integers
echo 10 <=> 10; // 0
echo 10 <=> 20; // -1
echo 20 <=> 10; // 1
// Floats
echo 1.5 <=> 1.5; // 0
echo 1.5 <=> 2.5; // -1
echo 2.5 <=> 1.5; // 1
// Strings
echo "a" <=> "a"; // 0
echo "a" <=> "b"; // -1
echo "b" <=> "a"; // 1
// Comparison is case-sensitive
echo "B" <=> "a"; // -1
echo "a" <=> "aa"; // -1
echo "zz" <=> "aa"; // 1
// Arrays
echo [] <=> []; // 0
echo [1, 2, 3] <=> [1, 2, 3]; // 0
echo [1, 2, 3] <=> []; // 1
echo [1, 2, 3] <=> [1, 2, 1]; // 1
echo [1, 2, 3] <=> [1, 2, 4]; // -1
// Objects
$a = (object) ["a" => "b"];
$b = (object) ["a" => "b"];
echo $a <=> $b; // 0
$a = (object) ["a" => "b"];
$b = (object) ["a" => "c"];
echo $a <=> $b; // -1
$a = (object) ["a" => "c"];
$b = (object) ["a" => "b"];
echo $a <=> $b; // 1
// only values are compared
$a = (object) ["a" => "b"];
$b = (object) ["b" => "b"];
echo $a <=> $b; // 1