我在 PHP 函数外部创建一个数组,并在函数内部调用 global,但我的函数无法看到该数组。该函数也被递归调用。知道我做错了什么吗?
$node_types = array( 1 => 'testproject',
2 => 'testsuite',
3 => 'testcase');
function get_subtree($node_id,&$node_list) {
global $node_types;
foreach ($node_types as $key) {
echo("node_types: " . $key . "<BR>");
}
....
get_subtree($node_id,$node_list);
}
Run Code Online (Sandbox Code Playgroud)
我的错误:
Notice: Undefined variable: node_types in ...
Run Code Online (Sandbox Code Playgroud)
谢谢