note 82639 added to control-structures.elseif

From: Date: Sat, 19 Apr 2008 20:36:53 +0000
Subject: note 82639 added to control-structures.elseif
Groups: php.notes 
Request: Send a blank email to php-notes+get-138543@lists.php.net to get a copy of this message
Based on a test averaged over one hundred attempts (whereby one billion iterations occured during each attempt) on the alternative "else if" and "elseif" methods, I have observed that the "elseif" method completes its task more than 99% faster than the "else if" method. This test was completed on a MacBook Pro with Mac OS 10.4.11 running an Apache server with PHP 5.2.3. The conditional statements used within the iterations were the following (with $x = 10): <?php if ($x = 0) { $res = 'f'; } else if ($x = 1 || $x = 2 || $x = 3 || $x = 4 || $x = 5 || $x = 6 || $x = 7 || $x = 8 || $x = 9 || $x = 10) { $res = 'v'; } ?> <?php if ($x = 0) { $res = 'f'; } elseif ($x = 1 || $x = 2 || $x = 3 || $x = 4 || $x = 5 || $x = 6 || $x = 7 || $x = 8 || $x = 9 || $x = 10) { $res = 'v'; } ?> ---- Server IP: 216.235.15.211 Probable Submitter: 76.10.148.3 ---- Manual Page -- http://www.php.net/manual/en/control-structures.elseif.php Edit -- https://master.php.net/note/edit/82639 Del: integrated -- https://master.php.net/note/delete/82639/integrated Del: useless -- https://master.php.net/note/delete/82639/useless Del: bad code -- https://master.php.net/note/delete/82639/bad+code Del: spam -- https://master.php.net/note/delete/82639/spam Del: non-english -- https://master.php.net/note/delete/82639/non-english Del: in docs -- https://master.php.net/note/delete/82639/in+docs Del: other reasons-- https://master.php.net/note/delete/82639 Reject -- https://master.php.net/note/reject/82639 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138543) next »