Saturday, 17 August 2013

Return in a function while in loop

Return in a function while in loop

I have a function, which checks a query, and then uses a while loop to
extract data, I would like to return this data but I still want it to
increment, but I read that return terminates a function, and thus would
make it unable to increment. Is there a way around this? $this->messages =
array(); while($row = $data) { $this->messages[$i]['id'] = $row['id'];
$this->messages[$i]['title'] = $row['title'];
$this->messages[$i]['message'] = $row['message']; $i++;
This loop is inside the function, I want to continue until the loop is
done, but then I can't return any values.. is there a work around this?
Thank you

No comments:

Post a Comment