note 48348 added to control-structures.switch

From: Date: Mon, 20 Dec 2004 12:52:19 +0000
Subject: note 48348 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-82084@lists.php.net to get a copy of this message
Be carefull: If you want to test the return of a function, you have to use switch, because if you use 'if' and 'ifelse', your function will be executed every time again. For example if use use the following construct: if(file_get_contents('file.htm', 0) == 'typ1') { // Do one thing } ifelse(file_get_contents('file.htm', 0) == 'typ2') { // Do the second thing } ifelse(file_get_contents('file.htm', 0) == 'typ3') { // Do the third thing } The file will be requested 3 times!!! If you use the following: switch (file_get_contents('file.htm', 0)) { case 'typ1': // Do one thing break; case 'typ2': // Do the second thing break; case 'typ3': // Do the third thing } The file will be requested only once!!! ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48348 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48348&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48348&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48348&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48348&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48348&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48348&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48348&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82084) next »