note 94498 deleted from control-structures.break by danbrown

From: Date: Sun, 08 Nov 2009 20:50:27 +0000
Subject: note 94498 deleted from control-structures.break by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162652@lists.php.net to get a copy of this message
Note Submitter: Richard at reg dot nl ---- 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.

« previous php.notes (#162652) next »