eg.
I have an array of objects that I would like to access using an index syntax instead of having to use the foreach loop in php.
I cant seem to use a normal index like Person[0]->Height to access the Height property of the person at position 0 in the array. In C# it would have been so simple as Person[0].Height
Am I doing something wrong or is there anyway I could do something similar?
Code:
class Person
{
public $Height;
public $Age;
}
$firstPerson = new Person();
$firstPerson->Height = 136;
$firstPerson->Age = 26;
$secondPerson = new Person();
$secondPerson->Height = 124;
$secondPerson->Age = 18;
Persons = array($firstPerson, $secondPerson);
I have an array of objects that I would like to access using an index syntax instead of having to use the foreach loop in php.
I cant seem to use a normal index like Person[0]->Height to access the Height property of the person at position 0 in the array. In C# it would have been so simple as Person[0].Height
Am I doing something wrong or is there anyway I could do something similar?