note 83837 deleted from control-structures.foreach by tularis
| From: | tularis@php.net | Date: | Sat, 14 Jun 2008 21:06:54 +0000 |
| Subject: | note 83837 deleted from control-structures.foreach by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140439@lists.php.net to get a copy of this message | ||
Note Submitter: fatmuemoo at gmail dot com
----
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.