note 54099 added to control-structures.while

From: Date: Thu, 23 Jun 2005 16:15:34 +0000
Subject: note 54099 added to control-structures.while
Groups: php.notes 
Request: Send a blank email to php-notes+get-90846@lists.php.net to get a copy of this message
Watch this: <? $arr = array(1,2,3); $arr2 = array_fill(0,85,"Casa"); while(list($k, $v) = each($arr)){ while(list($k2, $v2) = each($arr2)){ if($k2 == 84){ //break 2 will be executed break 2; } } break; } echo $v2; //expected value "Casa" is OK ?> but in this case... <? $arr = array(1,2,3); $arr2 = array_fill(0,85,"Casa"); while(list($k, $v) = each($arr)){ while(list($k2, $v2) = each($arr2)){ if($k2 == 90){ //break 2 will not be executed break 2; } } break; } echo $v2; //expected value "Casa" is NULL (why??) ?> ...to make this work... <? $arr = array(1,2,3); $arr2 = array_fill(0,85,"Casa"); while(list($k, $v) = each($arr)){ while(list($k2, $v2) = each($arr2)){ if($k2 == 90){ //break 2 will not be executed break 2; } else { //but... $aux = $v2; } } break; } echo $v2; //still NULL echo $aux; //print Casa as expected in $v2 ?> This is a bug??? ---- Manual Page -- http://www.php.net/manual/en/control-structures.while.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54099 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54099&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54099&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54099&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54099&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54099&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54099&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54099&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90846) next »