Re: find all keys in 2D array
- From: Karel de Vos <ng@xxxxxx>
- Date: Thu, 25 May 2006 14:08:26 +0200
There are more ways to do this. Here's one:
// where $inputar = Array(...)
$tmp_ar = array();
foreach($inputar as $item) {
if ($item['type']=='d')
$tmp_ar[] = $item;
}
// now $tmp_ar contains al items with type 'd'
foreach($tmp_ar as $key1=>$item1) {
foreach($inputar as $item2) {
if ($item2['id']==$item1['id'].':start')
$tmp_ar[$key1]['level'] = $item2['level'];
}
}
// now $tmp_ar has items that have a matching item in $inputar (+'start') changed to the 'level' value of that item
mtBrains wrote:
I have a 2D array. I want to find all sub array items, that are of.
[type] => d.
then take the [id] of the found sub items, find any subitems that have
the same id with ":start" attached and take their [level] remove that
subitem and attach [level] to the type d item.
It's easier to explain with some example. I've got the followin array:
Array
(
[0] => Array
(
[id] => assortments
[type] => d
[level] => 1
)
[1] => Array
(
[id] => assortments:categories
[type] => d
[level] => 2
)
[2] => Array
(
[id] => assortments:start
[type] => f
[level] => 3
)
)
I want it to look like this:
Array
(
[0] => Array
(
[id] => assortments
[type] => d
[level] => 3
)
[1] => Array
(
[id] => assortments:categories
[type] => d
[level] => 2
)
)
Notice [3] is gone. It had the same id as [0] with a ':start' attached.
The [level] of that array sub item was then updated on item [0].
TIA..martin
- References:
- find all keys in 2D array
- From: mtBrains
- find all keys in 2D array
- Prev by Date: Re: regular expression problem
- Next by Date: Re: calculating complete quarters between two dates
- Previous by thread: find all keys in 2D array
- Next by thread: HTML Email Form - PLEASE HELP!!!
- Index(es):