i need to define the array values as need. Here i say that the value will be 0 to 2. But i need someway to say the value can be null and also it can be 0 to 1000.
$apartment = array(
0,
1,
2
);
foreach ($apartment AS $apt) {
$userApt = $area->getApartments()->get($apt)->getApartment();
echo $userApt . "<br>";
}
Please note that the value can be 0 and it should stop where there is no available value ...
i mean if get(0) is available it should get the value, if get(1) is not available it should stop there and do nothing , so the main purpose is to get the value where it is available, when it is not available, do nothing...
According to your lasts edits, there is no need to build such an array. You can get your objects directly within the loop.
<?php
for($i = 0; $i <= 1000; ++$i) {
$userApt = $area->getApartments()->get($i);
if(!$userApt) {
break;
} else {
var_dump($userApt->getApartment());
}
}
This would stop as soon as an object cannot be retrieved.