Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8469

Re: unset multidimensional array element

From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: unset multidimensional array element
Date 2013-02-24 17:25 +0100
Message-ID <aout88Ffoa0U1@mid.uni-berlin.de> (permalink)
References <1de87c2e-dd81-475a-8516-85c0885dca9a@p5g2000yqj.googlegroups.com> <aoujigFdhp1U1@mid.uni-berlin.de> <4683f6ee-6169-46f8-9e21-0ec94f5c5d1f@googlegroups.com>

Show all headers | View raw


Am 24.02.2013 16:36, schrieb catebekensail@yahoo.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.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

unset multidimensional array element cate <catebekensail@yahoo.com> - 2013-02-23 16:18 -0800
  Re: unset multidimensional array element Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-23 20:17 -0500
    Re: unset multidimensional array element cate <catebekensail@yahoo.com> - 2013-02-23 17:19 -0800
      Re: unset multidimensional array element Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-23 20:21 -0500
        Re: unset multidimensional array element cate <catebekensail@yahoo.com> - 2013-02-23 17:24 -0800
          Re: unset multidimensional array element Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-23 20:34 -0500
            Re: unset multidimensional array element cate <catebekensail@yahoo.com> - 2013-02-23 17:40 -0800
  Re: unset multidimensional array element "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-02-24 14:40 +0100
    Re: unset multidimensional array element catebekensail@yahoo.com - 2013-02-24 07:36 -0800
      Re: unset multidimensional array element "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-02-24 17:25 +0100
      Re: unset multidimensional array element Captain Paralytic <paul_lautman@yahoo.com> - 2013-02-25 04:01 -0800
      Re: unset multidimensional array element Jerry Stuckle <jstucklex@attglobal.net> - 2013-02-25 11:13 -0500

csiph-web