note 50900 deleted from control-structures.while by cmb

From: Date: Wed, 30 Sep 2020 11:30:29 +0000
Subject: note 50900 deleted from control-structures.while by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215483@lists.php.net to get a copy of this message
Note Submitter: ---- virtualjosh at yahoo dot com (Hosh) wrote on: 16-Aug-2003 12:52 The speedtest is interesting. But the seemingly fastest way contains a pitfall for beginners who just use it because it is fast and fast is cool ;) Walking through an array with next() will cut of the first entry, as this is the way next() works ;) If you really need to do it this way, make sure your array contains an empty entry at the beginning. Another way would be to use <?php while ($this = current($array) ){ do_something($this); next($array); } ?> There is an impact on speed for sure but I did not test it. I would advise to stick with conventional methods because current(),next() in while loops is too error prone for me.

« previous php.notes (#215483) next »