null

显式赋值为null,可以触发内存回收。

[运行代码]

echo "<pre>";
echo memory_get_usage(), "\n";
$a = [];
for($i =0; $i < 1000; $i++){
    $a[] = $i;
}
echo memory_get_usage(), "\n";
$a = null;
echo memory_get_usage(), "\n";

[执行结果]

226536
371192
226824

如果数组中不存在某个元素,也会返回null, null == false

[运行代码]

$a = [];
var_dump($a["xxx"]);

[执行结果]

<br />
<b>Notice</b>:  Undefined index: xxx in <b>/data/lab/3yeug5xk/index.php</b> on line <b>4</b><br />
NULL