在一个递归函数中,设置静态变量前,需要先isset吗?
<?php
function test($array)
{
static $data = [];
//if (!isset($data)) {
// static $data = [];
//}
foreach ($array as $item) {
if (is_array($item)) {
test($item);
} else {
$data[] = $item;
}
}
}
$arr = [[1,2,3],3,4,[5,6]];
test($arr);
通常我是不会 isset 的,按照我的理解 static 不会定义第二遍
推荐文章: