|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-10-02 20:32 UTC] fa@php.net
[2009-10-02 21:21 UTC] matt at plasmacoustics dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 02:00:01 2026 UTC |
Description: ------------ I feel the SWITCH documentation might best include code for dealing with inequalities in a CASE, using switch(TRUE). People are posting User Notes with implementations relying on type conversion of a random number to boolean TRUE, as the switch argument. This will cause a confusing logic error any time the argument is zero. Here's an example to help people get the right idea: Reproduce code: --------------- <?php $rand=rand(-3,+3); // Good use of switch() with inequalities: note TRUE is the argument, and all rand() outcomes are covered without overlap switch(TRUE) { case $rand < 0: print "$rand is less than zero"; break; case $rand == 0: print "$rand is equal to zero"; break; case $rand > 0: print "$rand is greater than zero"; break; } ?>