Menus

Saturday, 29 August 2015

PHP knowledge for studying of Yii framework.



Two conditions in a for loop


$s = 1;

while ($result_row = mysql_fetch_assoc($query) && $s < 5)
{
echo $result_row['id'];
$s++;
}



break (PHP 4, PHP 5)

break ends execution of the current for, foreach, while, do-while or switch structure.


Examples:

            for($i=0;$i<count($model);$i++)
                    {
                        echo $model[$i]['month_year'];    
                        if($i<12) break;
                    }  




$s=1
while ($result_row = mysql_fetch_assoc($query))
{
    echo $result_row['id'];
    $s++;
    if($s>5){
        break;
    }
}







No comments:

Post a Comment