Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
空数组获取我的PHP类中的其他数组值 classmytest{ 公帑1元; 公帑2元; 公共函数构造() { $this->$array1=array(); $this->$array2=array(); echo“你好,我是构造函数”; $this->m1(); } 函数m1(){ 回声“内部功能”; 对于($i=0;$i$array1[]=$i; } 回音'数组1'; 打印(数组值($this->$array1)); 回波'阵列2'; 打印(数组值($this->$array2)); } } 新MyTest; 这是输出:_Php_Arrays - Fatal编程技术网

空数组获取我的PHP类中的其他数组值 classmytest{ 公帑1元; 公帑2元; 公共函数构造() { $this->$array1=array(); $this->$array2=array(); echo“你好,我是构造函数”; $this->m1(); } 函数m1(){ 回声“内部功能”; 对于($i=0;$i$array1[]=$i; } 回音'数组1'; 打印(数组值($this->$array1)); 回波'阵列2'; 打印(数组值($this->$array2)); } } 新MyTest; 这是输出:

空数组获取我的PHP类中的其他数组值 classmytest{ 公帑1元; 公帑2元; 公共函数构造() { $this->$array1=array(); $this->$array2=array(); echo“你好,我是构造函数”; $this->m1(); } 函数m1(){ 回声“内部功能”; 对于($i=0;$i$array1[]=$i; } 回音'数组1'; 打印(数组值($this->$array1)); 回波'阵列2'; 打印(数组值($this->$array2)); } } 新MyTest; 这是输出:,php,arrays,Php,Arrays,有人能告诉我为什么会发生这种情况吗:-(?不要在对成员变量的引用上加上美元符号 class MyTest{ public $array1; public $array2; public function __construct() { $this->$array1 = array(); $this->$array2 = array(); echo "Hello, I'm constructor<


有人能告诉我为什么会发生这种情况吗:-(?

不要在对成员变量的引用上加上美元符号

class MyTest{

    public $array1;
    public $array2;


    public function __construct()
    {
        $this->$array1 = array();
        $this->$array2 = array();
        echo "Hello, I'm constructor<br/>";
        $this->m1();
    }

    function m1(){

        echo 'inside function';

        for($i=0;$i<10;$i++){
            $this->$array1[] = $i;
        }

        echo '<br/>Array 1<br/>';
        print_r(array_values($this->$array1));

        echo '<br/>Array 2<br/>';
        print_r(array_values($this->$array2));

    }

}

new MyTest;
应该是

$this->$array1
$this->$array2

既然你问了这个问题,我想你没有在PHP中启用错误报告,或者你会看到一堆可能会帮助你弄清楚这是怎么回事的通知。请检查你的开发环境。@don'tPanic,非常有用的信息。谢谢。没问题。祝你好运!:)
$this->array1
$this->array2