|
Posted by tg-php on 10/12/05 19:43
If I understand what you're asking, then maybe this will help:
$arrset1 = array("Apples" => 3, "Oranges" => 5, "Apricots" => 1);
$arrset2 = array("Couches" => 6, "Chairs" => 2, "Benches" => 5);
$alldataarr["Fruits"] = $arrset1;
$alldataarr["Furniture"] = $arrset2;
Say we want to remove "Chairs", and let's do it the hard way:
foreach ($alldataarr as $key => $data) {
foreach ($data as $subkey => $subdata) {
if ($subkey == "Chairs) {
unset($alldataarr[$key][$subkey]);
}
}
}
using foreach $arr as $key => $data you can get the key/index name as well as the actual value stored in that part of your array. Then all you have to do is refer back up to the main array using the current $key/$subkey values as your indexes.
Basic example, but I think you can modify this to work with what you're doing.
Let me know if you have any questions about this example.
-TG
= = = Original message = = =
Hi all,
I'm really struggling here! I have a large, multi-dimensional array that
I want to "clean-up" a bit before committing to a database.
I want to remove quite a bit of the array but using the KEYs not the
values. I know the keys I want to keep and I know the keys I want to get
rid of. I want to keep the structure and sequence of the array in tact.
All of the array traversing functions in PHP seem to either: only work
on the values, or do not allow the removal of elements of the array!
Can anyone offer a clue bat to a tired old array walker!
Thanks
Alan
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
Navigation:
[Reply to this message]
|