kimdan Posted June 30, 2015 Share Posted June 30, 2015 PHP Freaks forum users, Thanks in advance for your interest in helping. This is my second post, I have general, basic computer programming experience and am beginning PHP. I don't see why the following loop works (PHP), given the variable $sqli1_dat an object taken from a mysqli query. the loop -- while( $x = $sqli1_dat->fetch_row() ) { printf("%s\n", $x[0] ); } this prints column 0. I am aware that fetch_row increments the pointer every time it's called. But I do not follow the loop condition expression. It looks like a variable assignment, like $x = 5? But the loop condition needs to be a truth-value, such as the expression $x == 5 Dan Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted June 30, 2015 Solution Share Posted June 30, 2015 (edited) It looks like a variable assignment yes, it is. But the loop condition needs to be a truth-value and, yes, it is. it's testing the result of the assignment statement, which will be the value that was assigned. when there are no more rows, the fetch statement returns a false, which will be assigned to the $x variable, and the value tested for the loop condition will be a false and the loop will end. from the documentation for the assignment operator - The value of an assignment expression is the value assigned. That is, the value of "$a = 3" is 3. This allows you to do some tricky things: Edited June 30, 2015 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.