Dynamic access to a PHP array

后端 未结 4 397
逝去的感伤
逝去的感伤 2021-01-13 05:27

I tried to access with $this->$arrDataName[$key] on the element with the key $key from the array $this->$arrDataName. But PHP in

4条回答
  •  有刺的猬
    2021-01-13 06:29

    myArray = array('FooBar');
                $arrayName = 'myArray';
                echo $this->{$arrayName}[0];
            }
        }
        new Foo;
    

    This worked perfectly for me, it printed FooBar.

提交回复
热议问题