Re: unset multidimensional array element [message #180541 is a reply to message #180534] |
Mon, 25 February 2013 12:01 |
Captain Paralytic
Messages: 204 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Feb 24, 3:36 pm, catebekens...@yahoo.com wrote:
>> This is the behaviour PHP programmers IMO like. Imagine you have a unique database
>
>> key as index, I would not like it to be renumbered after deletion of one entry.
>
>> /Str.
>
> Me neither ... :-)
>
> $a = array(1,2,3,4,5,9,8,7,6);
> unset($a[4]);
> print_r($a);
> $ar = array_reverse($a);
> print_r($ar);
If you want to renumber your array without changing the natural order
then use array_merge($a), rather than array_reverse($a). But like the
others here, I urge you to think in terms of collections (where
foreach operates), rather than numeric array indexes.
|
|
|