I need to have a function that sort of acts like mysql resources sometimes do, where you have to “fetch” something as part of a loop until it returns false.
I have something like:
while ($variable = $object->method())
{
// Do stuff with variable here
}
I’m trying to figure out how, on my object, to best keep track of what to send from the method.
class object {
$values = array(1, 2);
public function method()
{
// First call should return 1, second should return 2, and any subsequent calls should return FALSE
// Not sure now what to do
// return $values[$i];
}
}
You can simply
return array_shift($values)in your case. (docs).