Heya guys, now ive never done this method before and i just tried it to see if it would work and it works like a dream.
Usually people tend to do this way.
$tags = array();
while($row = $statement->FetchObject())
{
$tags[] = $row;
}
but would it be faster or just less code if i done it this way.
$tags = array();
while($tags[] = $statement->FetchObject()){}
Just Curious that's all
Update:
I do understand that Cleaner code is much better then Less code, but as I never used this method before it was mere curiosity for pros and cons.
The general issue is that to exit the while
loop, a "false" result needs to be returned. In your second example, that means there will be a "false" value (which is likely not what you want) at the end of your array.
This is not an issue for the traditional approach because the "false" value is given to $row
and never applied to the array.
As for performance, or readability, they're non-issues since the code doesn't do what you want it to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With