In this case I would create a getter method in your mainObj class, something like this:-
class mainObj
{
public $name = 0;
public $address = '';
public $someArray = array(1 => 'one' ,2 => 'two', 3 => 'three', 4 => 'four');
public function getSomeArray()
{
return $this->someArray;
}
}
Then you can access $someArray
quite easily:-
$obj1 = new mainObj();
$obj1->name = 1;
$obj2 = new mainObj();
$obj2->name = 2;
$obj3 = new mainObj();
$obj3->name = 3;
$objArray = array($obj1, $obj2, $obj3);
foreach($objArray as $obj){
echo "Object: {$obj->name}<br/>\n";
foreach($obj->getSomeArray() as $key => $value){
echo "Key: $key , Value: $value<br/>\n";
}
}
Output:-
Object: 1
Key: 1 , Value: one
Key: 2 , Value: two
Key: 3 , Value: three
Key: 4 , Value: four
Object: 2
Key: 1 , Value: one
Key: 2 , Value: two
Key: 3 , Value: three
Key: 4 , Value: four
Object: 3
Key: 1 , Value: one
Key: 2 , Value: two
Key: 3 , Value: three
Key: 4 , Value: four