我在一个wordpress主题中有以下情况,我想在一个名为navigation.php的文件中修改
$array_test = array (1,2,3,4);
function func1()
{
global $array_test;
echo "test"; // to ensure that the function has been called
echo $array_test[2]; // this writes nothing, though the function is being called
}
在header.php文件中,函数func1
正在被调用,但$array_test[2]
的值仍然无法访问,
你有什么想法吗?
编辑:我怀疑这是wordpress或主题的问题,但我不确定主题是免费的health_care_wp_theme
在navigation.php中(如果该文件中没有类,则定义一个)
class Nav
{
public $array_test = array(1,2,3,4);
public function func1()
{
echo "test"; // to ensure that the function has been called
return $this->array_test[2];
}
public function access_within_class()
{
print_r($this->array_test);
}
}
在header。php include 'path/to/navigation.php';
$nav = new Nav();
$the_array = $nav->func1();
echo $the_array;