Re: find all keys in 2D array



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

.