Re: [PHP] Quick array question

2001-10-31 Thread Christian Reiniger

On Tuesday 30 October 2001 20:33, David Yee wrote:
> Well for that example I'm using 0 as the index for the first element of
> the array, so deleting element #2 results in 3 being deleted.  BTW to
> correct myself in the second example I gave I want:
>
> $a = (1,2,4,5) instead of (1,2,3,4).
>
> > $a = array(1,2,3,4,5)
> >
> > unset($a[2]);
> >
> > $a now = (1, 2, NULL, 4, 5), but I want (1, 2, 3, 4).

Now do you want (1, 2, 4, 5) or (1, 2, 3,4 ) ?

If second:
So you want the array always to contain a continuous list of numbers
(1..n) ? So it's irrelevant *what* element of the array you delete, only 
*how many* elements you delete?
Why not just store the maximum value then and use
$MaxVal-- instead of unset ($a[something]),
$Index - 1 instead of $a[$Index]

?

If the first: remember that arrays in PHP are always associative. So you 
get (0 => 1, 1 => 2, 3 => 4, 4 => 5)
if you want the keys "reordered" you could use array_values() on that..

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

"Never doubt that a small group of thoughtful, committed people can
change the world...
Indeed, it's the only thing that ever has."

- Margaret Mead

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Quick array question

2001-10-30 Thread David Yee

Well for that example I'm using 0 as the index for the first element of the
array, so deleting element #2 results in 3 being deleted.  BTW to correct
myself in the second example I gave I want:

$a = (1,2,4,5) instead of (1,2,3,4).

> $a = array(1,2,3,4,5)
>
> unset($a[2]);
>
> $a now = (1, 2, NULL, 4, 5), but I want (1, 2, 3, 4).

Thanks.

David

- Original Message -
From: "Sam Masiello" <[EMAIL PROTECTED]>
To: "David Yee" <[EMAIL PROTECTED]>
Sent: Tuesday, October 30, 2001 10:53 AM
Subject: Re: [PHP] Quick array question


>
> Very interesting delete function..
>
> I assume $b should have values (1,3,4,5), not (1,2,4,5) :)
>
> --Sam
>
>
>
> - Original Message -
> From: "David Yee" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, October 30, 2001 2:03 PM
> Subject: [PHP] Quick array question
>
>
> Hi.  Is there an array function that deletes an array element (that's not
at
> the beginning or the end of the array) and return the resultant array?
E.g.
> this is what I want to do:
>
> $a = array(1, 2, 3, 4, 5);
>
> $b = array_element_delete_function($a, 2);
>
> $b now has 4 elements with the following values: (1, 2, 4, 5)
>
> Thanks.
>
> David
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Quick array question

2001-10-30 Thread David Yee

Got it- thanks Philip.

David

- Original Message -
From: "Philip Olson" <[EMAIL PROTECTED]>
To: "David Yee" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, October 30, 2001 11:27 AM
Subject: Re: [PHP] Quick array question


> Check out this post:
>
>   http://marc.theaimsgroup.com/?l=php-general&m=100096614905023
>
> Which reads:
>
> Here's an example using unset() and array_splice(), notice the subtle
> difference:
>
> 
> $foo = array('a','b','c');
>
>   unset($foo[1]);
>
>   print_r($foo);// [0] => a [2] => c
>
> $bar = array('a','b','c');
>
>   $piece = array_splice ($bar, 1 ,1);
>
>   print_r($piece);  // [0] => b
>
>   print_r($bar);// [0] => a [1] => c
>
> ?>
>
> Okay, no need to check the old post now :)  Check out :
>
>   http://uk.php.net/array_slice
>   http://uk.php.net/array_splice
>
> regards,
> Philip Olson
>
>
> On Tue, 30 Oct 2001, David Yee wrote:
>
> > That doesn't seem to do what I want.  That would only unset the value
for
> > the element, but the element is still there.  E.g.
> >
> > $a = array(1,2,3,4,5)
> >
> > unset($a[2]);
> >
> > $a now = (1, 2, NULL, 4, 5), but I want (1, 2, 3, 4).
> >
> > David
> >
> > - Original Message -
> > From: "Matt Williams" <[EMAIL PROTECTED]>
> > To: "David Yee" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Tuesday, October 30, 2001 10:49 AM
> > Subject: RE: [PHP] Quick array question
> >
> >
> > > Just found this in the manual notes
> > >
> > > http://www.php.net/manual/en/ref.array.php
> > >
> > > To delete an element from an array in an easy way, use
> > > unset($array["element"]);...
> > >
> > > Funny those... manuals
> > >
> > > M:
> > >
> > > > -Original Message-
> > > > From: David Yee [mailto:[EMAIL PROTECTED]]
> > > > Sent: 30 October 2001 19:03
> > > > To: [EMAIL PROTECTED]
> > > > Subject: [PHP] Quick array question
> > > >
> > > >
> > > > Hi.  Is there an array function that deletes an array element
> > > > (that's not at the beginning or the end of the array) and return
> > > > the resultant array?  E.g. this is what I want to do:
> > > >
> > > > $a = array(1, 2, 3, 4, 5);
> > > >
> > > > $b = array_element_delete_function($a, 2);
> > > >
> > > > $b now has 4 elements with the following values: (1, 2, 4, 5)
> > > >
> > > > Thanks.
> > > >
> > > > David
> > > >
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
>
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Quick array question

2001-10-30 Thread David Yee

That doesn't seem to do what I want.  That would only unset the value for
the element, but the element is still there.  E.g.

$a = array(1,2,3,4,5)

unset($a[2]);

$a now = (1, 2, NULL, 4, 5), but I want (1, 2, 3, 4).

David

- Original Message -
From: "Matt Williams" <[EMAIL PROTECTED]>
To: "David Yee" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, October 30, 2001 10:49 AM
Subject: RE: [PHP] Quick array question


> Just found this in the manual notes
>
> http://www.php.net/manual/en/ref.array.php
>
> To delete an element from an array in an easy way, use
> unset($array["element"]);...
>
> Funny those... manuals
>
> M:
>
> > -Original Message-
> > From: David Yee [mailto:[EMAIL PROTECTED]]
> > Sent: 30 October 2001 19:03
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Quick array question
> >
> >
> > Hi.  Is there an array function that deletes an array element
> > (that's not at the beginning or the end of the array) and return
> > the resultant array?  E.g. this is what I want to do:
> >
> > $a = array(1, 2, 3, 4, 5);
> >
> > $b = array_element_delete_function($a, 2);
> >
> > $b now has 4 elements with the following values: (1, 2, 4, 5)
> >
> > Thanks.
> >
> > David
> >
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Quick array question

2001-10-30 Thread Matt Williams

Just found this in the manual notes

http://www.php.net/manual/en/ref.array.php

To delete an element from an array in an easy way, use
unset($array["element"]);...

Funny those... manuals

M: 

> -Original Message-
> From: David Yee [mailto:[EMAIL PROTECTED]]
> Sent: 30 October 2001 19:03
> To: [EMAIL PROTECTED]
> Subject: [PHP] Quick array question
> 
> 
> Hi.  Is there an array function that deletes an array element 
> (that's not at the beginning or the end of the array) and return 
> the resultant array?  E.g. this is what I want to do:
> 
> $a = array(1, 2, 3, 4, 5);
> 
> $b = array_element_delete_function($a, 2);
> 
> $b now has 4 elements with the following values: (1, 2, 4, 5)
> 
> Thanks.
> 
> David
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Quick array question

2001-10-30 Thread David Yee

Hi.  Is there an array function that deletes an array element (that's not at the 
beginning or the end of the array) and return the resultant array?  E.g. this is what 
I want to do:

$a = array(1, 2, 3, 4, 5);

$b = array_element_delete_function($a, 2);

$b now has 4 elements with the following values: (1, 2, 4, 5)

Thanks.

David