note 83837 added to control-structures.foreach
| From: | fatmuemoo at gmail dot com | Date: | Sat, 14 Jun 2008 04:05:11 +0000 |
| Subject: | note 83837 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140428@lists.php.net to get a copy of this message | ||
Ok, I'm Sorry if this is obvious to most of you, which I'm sure it is. But for me, It took
me a couple of hours to figure it out as I'm a relatively new programmer.
I wanted to build a new array from another array using fore each. This is what I came up with:
<?php
$count = 0;
foreach ($oldArray as $key => $value)
{
if (only_keep_values_u_want($value == true))
{
$newArray[$count] = $value;
$count++;
}
}
now you have $newArray with only the value you want based upon criteria from your
only_keep_values_u_want() function. I hope this helps some other newbies.
----
Server IP: 209.41.74.194
Probable Submitter: 68.236.252.117
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/83837
Del: integrated -- https://master.php.net/note/delete/83837/integrated
Del: useless -- https://master.php.net/note/delete/83837/useless
Del: bad code -- https://master.php.net/note/delete/83837/bad+code
Del: spam -- https://master.php.net/note/delete/83837/spam
Del: non-english -- https://master.php.net/note/delete/83837/non-english
Del: in docs -- https://master.php.net/note/delete/83837/in+docs
Del: other reasons-- https://master.php.net/note/delete/83837
Reject -- https://master.php.net/note/reject/83837
Search -- https://master.php.net/manage/user-notes.php