Re: unset multidimensional array element [message #180535 is a reply to message #180534] |
Sun, 24 February 2013 16:25   |
M. Strobel
Messages: 386 Registered: December 2011
Karma:
|
Senior Member |
|
|
Am 24.02.2013 16:36, schrieb catebekensail(at)yahoo(dot)com:
>
>> 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);
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[5] => 9
[6] => 8
[7] => 7
[8] => 6
)
> $ar = array_reverse($a);
> print_r($ar);
But:
$a = array(1=>'one',2=>'two',3=>'three',4=>'four');
unset($a[2]);
print_r($a);
Array
(
[1] => one
[3] => three
[4] => four
)
It must be difficult to understand for the beginner, but in fact "it just works" if
you set the index.
I counted 47 array functions with "array" in the name, and about the same number with
other names (http://php.net/manual/en/function.array.php), most of them I find fairly
unusable.
/Str.
|
|
|