note 94498 added to control-structures.break

From: Date: Sun, 08 Nov 2009 20:05:23 +0000
Subject: note 94498 added to control-structures.break
Groups: php.notes 
Request: Send a blank email to php-notes+get-162650@lists.php.net to get a copy of this message
Coryf88 at hotmail dot com made a mistake on 30-Aug-2008 08:51 $total must have an initial value of 1 instead of 0. Only then the answers below are right; <?php $total = 1; // CHANGED VALUE TO 1 INSTEAD OF 0 switch($i) { case 6: $total = 99; break; case 1: $total += 1; case 2: $total += 2; case 3: $total += 3; case 4: $total += 4; case 5: $total += 5; } ?> Using the above snippet, all of the following would be true: If $i = 6, $total would = 99. If $i = 5, $total would = 5. If $i = 4, $total would = 9. If $i = 3, $total would = 12. If $i = 2, $total would = 14. If $i = 1, $total would = 15. ---- Server IP: 69.147.83.197 Probable Submitter: 82.93.38.225 ---- Manual Page -- http://www.php.net/manual/en/control-structures.break.php Edit -- https://master.php.net/note/edit/94498 Del: integrated -- https://master.php.net/note/delete/94498/integrated Del: useless -- https://master.php.net/note/delete/94498/useless Del: bad code -- https://master.php.net/note/delete/94498/bad+code Del: spam -- https://master.php.net/note/delete/94498/spam Del: non-english -- https://master.php.net/note/delete/94498/non-english Del: in docs -- https://master.php.net/note/delete/94498/in+docs Del: other reasons-- https://master.php.net/note/delete/94498 Reject -- https://master.php.net/note/reject/94498 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162650) next »