note 50267 deleted from control-structures.foreach by nlopess

From: Date: Wed, 23 Feb 2005 13:22:43 +0000
Subject: note 50267 deleted from control-structures.foreach by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-85428@lists.php.net to get a copy of this message
Note Submitter: spam at afoyi dot com ---- I had a requirement for looping through an array of values and assign the values to another array, skipping particular values. Normally I'd just use next(), but this doesn't seem to work inside a foreach(). My kludge was to do the following: <?php $tmp_array = array(1, 2, 3, 4, 5, 6); $new_array = array(); foreach ($tmp_array as $item) { $skip = FALSE; if ($item == 4) $skip = TRUE; if ($skip != TRUE) $new_array[] = $item; } ?>

« previous php.notes (#85428) next »