FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » unset multidimensional array element
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: unset multidimensional array element [message #180535 is a reply to message #180534] Sun, 24 February 2013 16:25 Go to previous messageGo to previous message
M. Strobel is currently offline  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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: preg_replace... I can't do it!!
Next Topic: simpletest vs phpunit vs ...
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat May 03 20:21:16 GMT 2025

Total time taken to generate the page: 0.04694 seconds