note 50267 added to control-structures.foreach
| From: | spam at afoyi dot com | Date: | Wed, 23 Feb 2005 12:48:44 +0000 |
| Subject: | note 50267 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85427@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50267
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50267&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50267&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50267&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50267&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50267&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50267&report=yes
Search -- http://master.php.net/manage/user-notes.php