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


Groups > comp.lang.php > #8460 > unrolled thread

unset multidimensional array element

Started bycate <catebekensail@yahoo.com>
First post2013-02-23 16:18 -0800
Last post2013-02-25 11:13 -0500
Articles 12 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  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

#8460 — unset multidimensional array element

Fromcate <catebekensail@yahoo.com>
Date2013-02-23 16:18 -0800
Subjectunset multidimensional array element
Message-ID<1de87c2e-dd81-475a-8516-85c0885dca9a@p5g2000yqj.googlegroups.com>
Is this correct?

I remove an element from a multidee array.  Numeric Indexing then
fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
unset.   It seems the a numeric index has graduated to a key.  (I
think I read that's the way php works)

Do I have to repack this to get sequential indexing to work or is
there a php way to remove elements and maintain a "numeric" indexs?

I suppose I could make it a rule to use the construct foreach, but I
do so love for(;;).

Thank you in advance.


array (
   array (1, 2, 3),
   array (4, 5, 6),
   array (7, 8, 9)
)

[toc] | [next] | [standalone]


#8461

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-02-23 20:17 -0500
Message-ID<kgbpm4$hcg$1@dont-email.me>
In reply to#8460
On 2/23/2013 7:18 PM, cate wrote:
> Is this correct?
>
> I remove an element from a multidee array.  Numeric Indexing then
> fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
> unset.   It seems the a numeric index has graduated to a key.  (I
> think I read that's the way php works)
>
> Do I have to repack this to get sequential indexing to work or is
> there a php way to remove elements and maintain a "numeric" indexs?
>
> I suppose I could make it a rule to use the construct foreach, but I
> do so love for(;;).
>
> Thank you in advance.
>
>
> array (
>     array (1, 2, 3),
>     array (4, 5, 6),
>     array (7, 8, 9)
> )
>

All arrays in PHP are associative (hashes).  If you remove an element, 
that key no longer exists.

You can renumber the array, or you can use operators like foreach(), 
current(), next(), etc. and not worry about the keys.

Very seldom do I need to care about the array indexes being in a 
specific order.
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8462

Fromcate <catebekensail@yahoo.com>
Date2013-02-23 17:19 -0800
Message-ID<a9d6534c-33b4-4d64-802e-9f40ff7860c6@l13g2000yqe.googlegroups.com>
In reply to#8461
On Feb 23, 7:17 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 2/23/2013 7:18 PM, cate wrote:
>
>
>
>
>
>
>
>
>
> > Is this correct?
>
> > I remove an element from a multidee array.  Numeric Indexing then
> > fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
> > unset.   It seems the a numeric index has graduated to a key.  (I
> > think I read that's the way php works)
>
> > Do I have to repack this to get sequential indexing to work or is
> > there a php way to remove elements and maintain a "numeric" indexs?
>
> > I suppose I could make it a rule to use the construct foreach, but I
> > do so love for(;;).
>
> > Thank you in advance.
>
> > array (
> >     array (1, 2, 3),
> >     array (4, 5, 6),
> >     array (7, 8, 9)
> > )
>
> All arrays in PHP are associative (hashes).  If you remove an element,
> that key no longer exists.
>
> You can renumber the array, or you can use operators like foreach(),
> current(), next(), etc. and not worry about the keys.
>
> Very seldom do I need to care about the array indexes being in a
> specific order.
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I don't think there is any alternative in php.  Thank you.

[toc] | [prev] | [next] | [standalone]


#8463

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-02-23 20:21 -0500
Message-ID<kgbpt1$hcg$2@dont-email.me>
In reply to#8462
On 2/23/2013 8:19 PM, cate wrote:
> On Feb 23, 7:17 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> On 2/23/2013 7:18 PM, cate wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> Is this correct?
>>
>>> I remove an element from a multidee array.  Numeric Indexing then
>>> fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
>>> unset.   It seems the a numeric index has graduated to a key.  (I
>>> think I read that's the way php works)
>>
>>> Do I have to repack this to get sequential indexing to work or is
>>> there a php way to remove elements and maintain a "numeric" indexs?
>>
>>> I suppose I could make it a rule to use the construct foreach, but I
>>> do so love for(;;).
>>
>>> Thank you in advance.
>>
>>> array (
>>>      array (1, 2, 3),
>>>      array (4, 5, 6),
>>>      array (7, 8, 9)
>>> )
>>
>> All arrays in PHP are associative (hashes).  If you remove an element,
>> that key no longer exists.
>>
>> You can renumber the array, or you can use operators like foreach(),
>> current(), next(), etc. and not worry about the keys.
>>
>> Very seldom do I need to care about the array indexes being in a
>> specific order.
>
> I don't think there is any alternative in php.  Thank you.
>

As I said - *in PHP* I very seldom need to care about the array indexes 
being in a specific order.  There are many ways of doing things with 
arrays - and you don't even need a numeric index.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8464

Fromcate <catebekensail@yahoo.com>
Date2013-02-23 17:24 -0800
Message-ID<c62e82c1-2d97-42d5-9b6a-bc1c8096c553@5g2000yqz.googlegroups.com>
In reply to#8463
On Feb 23, 7:21 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 2/23/2013 8:19 PM, cate wrote:
>
>
>
>
>
>
>
>
>
> > On Feb 23, 7:17 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> On 2/23/2013 7:18 PM, cate wrote:
>
> >>> Is this correct?
>
> >>> I remove an element from a multidee array.  Numeric Indexing then
> >>> fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
> >>> unset.   It seems the a numeric index has graduated to a key.  (I
> >>> think I read that's the way php works)
>
> >>> Do I have to repack this to get sequential indexing to work or is
> >>> there a php way to remove elements and maintain a "numeric" indexs?
>
> >>> I suppose I could make it a rule to use the construct foreach, but I
> >>> do so love for(;;).
>
> >>> Thank you in advance.
>
> >>> array (
> >>>      array (1, 2, 3),
> >>>      array (4, 5, 6),
> >>>      array (7, 8, 9)
> >>> )
>
> >> All arrays in PHP are associative (hashes).  If you remove an element,
> >> that key no longer exists.
>
> >> You can renumber the array, or you can use operators like foreach(),
> >> current(), next(), etc. and not worry about the keys.
>
> >> Very seldom do I need to care about the array indexes being in a
> >> specific order.
>
> > I don't think there is any alternative in php.  Thank you.
>
> As I said - *in PHP* I very seldom need to care about the array indexes
> being in a specific order.  There are many ways of doing things with
> arrays - and you don't even need a numeric index.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Never an need for order (mumeric) is quite a statement.  :-)

[toc] | [prev] | [next] | [standalone]


#8465

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-02-23 20:34 -0500
Message-ID<kgbqlp$knu$1@dont-email.me>
In reply to#8464
On 2/23/2013 8:24 PM, cate wrote:
> On Feb 23, 7:21 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> On 2/23/2013 8:19 PM, cate wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Feb 23, 7:17 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>> On 2/23/2013 7:18 PM, cate wrote:
>>
>>>>> Is this correct?
>>
>>>>> I remove an element from a multidee array.  Numeric Indexing then
>>>>> fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
>>>>> unset.   It seems the a numeric index has graduated to a key.  (I
>>>>> think I read that's the way php works)
>>
>>>>> Do I have to repack this to get sequential indexing to work or is
>>>>> there a php way to remove elements and maintain a "numeric" indexs?
>>
>>>>> I suppose I could make it a rule to use the construct foreach, but I
>>>>> do so love for(;;).
>>
>>>>> Thank you in advance.
>>
>>>>> array (
>>>>>       array (1, 2, 3),
>>>>>       array (4, 5, 6),
>>>>>       array (7, 8, 9)
>>>>> )
>>
>>>> All arrays in PHP are associative (hashes).  If you remove an element,
>>>> that key no longer exists.
>>
>>>> You can renumber the array, or you can use operators like foreach(),
>>>> current(), next(), etc. and not worry about the keys.
>>
>>>> Very seldom do I need to care about the array indexes being in a
>>>> specific order.
>>
>>> I don't think there is any alternative in php.  Thank you.
>>
>> As I said - *in PHP* I very seldom need to care about the array indexes
>> being in a specific order.  There are many ways of doing things with
>> arrays - and you don't even need a numeric index.
>>
>
> Never an need for order (mumeric) is quite a statement.  :-)
>

First of all, I said "VERY SELDOM" - not never.  There are exceptions.

It's all about knowing the language and using the appropriate features. 
  It works quite well.

P.S. Please learn to trim signatures.  They shouldn't be copied.  Thanks.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8466

Fromcate <catebekensail@yahoo.com>
Date2013-02-23 17:40 -0800
Message-ID<03143c38-3762-42a8-b7c8-64e75fa6512c@n2g2000yqg.googlegroups.com>
In reply to#8465
On Feb 23, 7:34 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 2/23/2013 8:24 PM, cate wrote:
>
>
>
>
>
>
>
>
>
> > On Feb 23, 7:21 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> On 2/23/2013 8:19 PM, cate wrote:
>
> >>> On Feb 23, 7:17 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >>>> On 2/23/2013 7:18 PM, cate wrote:
>
> >>>>> Is this correct?
>
> >>>>> I remove an element from a multidee array.  Numeric Indexing then
> >>>>> fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
> >>>>> unset.   It seems the a numeric index has graduated to a key.  (I
> >>>>> think I read that's the way php works)
>
> >>>>> Do I have to repack this to get sequential indexing to work or is
> >>>>> there a php way to remove elements and maintain a "numeric" indexs?
>
> >>>>> I suppose I could make it a rule to use the construct foreach, but I
> >>>>> do so love for(;;).
>
> >>>>> Thank you in advance.
>
> >>>>> array (
> >>>>>       array (1, 2, 3),
> >>>>>       array (4, 5, 6),
> >>>>>       array (7, 8, 9)
> >>>>> )
>
> >>>> All arrays in PHP are associative (hashes).  If you remove an element,
> >>>> that key no longer exists.
>
> >>>> You can renumber the array, or you can use operators like foreach(),
> >>>> current(), next(), etc. and not worry about the keys.
>
> >>>> Very seldom do I need to care about the array indexes being in a
> >>>> specific order.
>
> >>> I don't think there is any alternative in php.  Thank you.
>
> >> As I said - *in PHP* I very seldom need to care about the array indexes
> >> being in a specific order.  There are many ways of doing things with
> >> arrays - and you don't even need a numeric index.
>
> > Never an need for order (mumeric) is quite a statement.  :-)
>
> First of all, I said "VERY SELDOM" - not never.  There are exceptions.
>
> It's all about knowing the language and using the appropriate features.
>   It works quite well.
>
> P.S. Please learn to trim signatures.  They shouldn't be copied.  Thanks.

lol  - It was my CNN mode.  Thanks again.

[toc] | [prev] | [next] | [standalone]


#8467

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-02-24 14:40 +0100
Message-ID<aoujigFdhp1U1@mid.uni-berlin.de>
In reply to#8460
Am 24.02.2013 01:18, schrieb cate:
> Is this correct?
> 
> I remove an element from a multidee array.  Numeric Indexing then
> fails because the it's no longer 0, 1, 2 but instead 0, 2 after the
> unset.   It seems the a numeric index has graduated to a key.  (I
> think I read that's the way php works)
> 
> Do I have to repack this to get sequential indexing to work or is
> there a php way to remove elements and maintain a "numeric" indexs?
> 
> I suppose I could make it a rule to use the construct foreach, but I
> do so love for(;;).
> 
> Thank you in advance.
> 
> 
> array (
>    array (1, 2, 3),
>    array (4, 5, 6),
>    array (7, 8, 9)
> )
> 
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.

[toc] | [prev] | [next] | [standalone]


#8468

Fromcatebekensail@yahoo.com
Date2013-02-24 07:36 -0800
Message-ID<4683f6ee-6169-46f8-9e21-0ec94f5c5d1f@googlegroups.com>
In reply to#8467
> 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);

[toc] | [prev] | [next] | [standalone]


#8469

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-02-24 17:25 +0100
Message-ID<aout88Ffoa0U1@mid.uni-berlin.de>
In reply to#8468
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.

[toc] | [prev] | [next] | [standalone]


#8475

FromCaptain Paralytic <paul_lautman@yahoo.com>
Date2013-02-25 04:01 -0800
Message-ID<78d0aedb-894c-4375-94b2-524be2ec2920@g16g2000vbf.googlegroups.com>
In reply to#8468
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.

[toc] | [prev] | [next] | [standalone]


#8476

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-02-25 11:13 -0500
Message-ID<kgg2hr$g83$1@dont-email.me>
In reply to#8468
On 2/24/2013 10:36 AM, catebekensail@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);
>

Which renumbers the indexes in the array.

The real question here is - WHY do you think you need the keys renumbered?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web