why are assignments in conditions bad?

后端 未结 6 438
长发绾君心
长发绾君心 2020-12-16 09:45

I am using NetBeans for PHP 6.5.

In my code I frequently use the following type of command:

if (($row = $db->get_row($sql))) {
        return $row         


        
6条回答
  •  無奈伤痛
    2020-12-16 10:28

    how would a code look like if you do not assign the $row value in the loop condition this would be much more complicated i think... although not that good to read for some maintainers, no? well you can do it like

    $next = mysql_fetch_assoc($result)
    do{
    ...
    ...
    ...
    
    $next = mysql_fetch_assoc($result) or break;
    }while ($next)
    

提交回复
热议问题