Option 1:
$foo = array($obj1, $obj2, $obj3);
for ($i = 0; $i < 1; $i++) {
echo $foo[$i]->attribute;
echo $foo[$i]->attribute2;
}
//shows obj1's attribute and attribute2
Option 2:
$foo = array($obj1, $obj2, $obj3);
$first_foo = array_shift($foo); /* now we only have the first index in the new array */
foreach ($first_foo as $object) {
echo $object->attribute;
echo $object->attribute2;
}
//shows obj1's attribute and attribute2
Option 3:
$foo = array($obj1, $obj2, $obj3);
$first_foo = $foo[0] /* now we just have an object, obj1 */
echo $first_foo->attribute;
echo $first_foo->attribute2;
//shows obj1's attribute and attribute2
I used Option 3, but all of these feel kinda lacking... how would you do this? Is the loop in options 1 and 2 worth it if you feel like easily pulling the first two instead of one later on? I.e. pulling the latest news article vs. pulling the latest two etc.