开发者

php conditionals

I'm having some trouble understanding how PHP parses conditionals.

For i开发者_StackOverflownstance,

while (list($id, $name, $salary) = mysql_fetch_row($result)) { ...}

(http://php.net/manual/en/function.list.php )

will evaluate true while the list can retrieve values. But printing the list will print the values contained within the list's variables. The manual also says that list() returns an array. How then, does the conditional know that the mysql fetch attempt was successful?

If it does return a boolean, how do you display it directly rather than

if(expr) echo 'true';

thanks!


list() assigns null to the variables listed if assigned a non-array or an array with too few items.

As null evaluates to false and an array with more than one item evaluates to true, the while loop is able to use the expression.

Small update

list() will trigger an "undefined index" E_NOTICE error if the array does not contain enough items

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜