so i'm having a php class like the following:
class myClass
{
function __construct()
{
$this->chart_data = array(1,2,3,4,5);
$this->captions = array("a", "b", "c", "d", "e");
}
}
is there a way to access the properties the same way like an associative array, like:
$obj = new myClass();
echo $obj['chart_data'];
echo $obj['captions'];
thanks!
From this answer you can try like this
$obj = (array) new myClass();
print_r($obj);
you can try
echo $obj->{'chart_data'};
echo $obj->{'captions'};