I'm fairly new to PHP and I am trying to return an array from a class function and then access its values like so:
<?php
class Foo
{
private $access;
public function setAccess($access)
{
$this->access = $access;
}
public function getAccess()
{
return $this->access;
}
}
$var = new Foo();
$var->setAccess(array(1,2,3,4));
$var2 = $var->getAccess()[2];
echo $var2;
?>
When I try to run a page with this code, I get the following:
Parse error: syntax error, unexpected '[' in arraytest.php on line 22
How can I access the values for my private arrays in my class?