This is a discussion on Removing elements from associate array. within the PHP General forums, part of the PHP Programming Forums category; Elo! I've got a problem with removing elements from associate array (php). Above you'll find a schematic structure ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Elo!
I've got a problem with removing elements from associate array (php). Above you'll find a schematic structure of my array: ARRAY ------ -> ELEMENT1 --> KEY1 => VALUE --> KEY2 => VALUE -> ELEMENT2 --> KEY1 => VALUE --> KEY2 => VALUE -> ELEMENT3 --> KEY1 => VALUE --> KEY2 => VALUE -> ELEMENT4 --> KEY1 => VALUE --> KEY2 => VALUE A script I try to prepare is going to remove a single element from this array leaving others "unharmed" :). If an array consists of only one element - that's ok, it is removed. If there are two records in an array, a try to delete second element throws off first one. The more elements in an array, the more mistakes occurs. I think that the problem is to find an id of an element (ex. ELEMENT2) (this is the element, that was identified in an foreach{} loop as an element to remove). I'm sure the solution is very simple, but i can't get it on (i'm not sure if this word construction is correct - i am not a native english speaking person). I was looking for the solution in some sources, but the only thing i have learnt is that to remove an element from an array is used a unset() command. That's correct - but how to get an id for an element to remove. If I could ask you to give me an example of deleting, let's say, second element from the structure i wrote above. MaciejK |