I'm trying to access an array declared in a class from a function within the same class. I've attempted a couple different ways to try to make it work but I'm relatively new to PHP. This is a snippet of my code
class Site extends CI_Controller {
var $dates = array(
"Task" => NULL,
"Date1" => NULL,
"Date2" => NULL,
"TimeDiff" => NULL
);
function index()
{
if($this->$dates['Date1'] != NULL && $this->$dates['Date2'] != NULL)
{
$this->$dates['TimeDiff'] = $this->$dates['Date2']->getTimestamp() - $this->$dates['Date1']->getTimestamp();
}
$this->load->view('usability_test', $this->$dates);
}
I also attempted using the global keyword as such
global $dates;
And I still receive a "Undefined variable" error regardless. Thanks!