RE: [PHP] Simple array question, part 2

2005-04-06 Thread Jay Blanchard
[snip]
I have a $data array like this:
[0] = 158
[1] = 169926
[2] = 169931
[3] = 169932
[4] = 169933
then when i delete the first one ([0] = 158) it becomes like this:
[1] = 169926
[2] = 169931
[3] = 169932
[4] = 169933

how do I get it to sort again from 0,1,2,3 etc?

I tried sort(), ksort(),reset() etcbut it still shows as starting
from 1
instead of resorting the keys starting from 0

what function should i lookup/use?
[/snip]

http://www.php.net/array_pop

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple array question, part 2

2005-04-06 Thread Josip Dzolonga
Ryan A wrote:
what function should i lookup/use?
Thanks,
Ryan
This will do the job :
$array = array_values($array);
Hope this helps,
--
Josip Dzolonga
http://josip.dotgeek.org
jdzolonga[at]gmail.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Simple array question, part 2

2005-04-06 Thread Philip Hallstrom
Hey,
I have a $data array like this:
   [0] = 158
   [1] = 169926
   [2] = 169931
   [3] = 169932
   [4] = 169933
then when i delete the first one ([0] = 158) it becomes like this:
[1] = 169926
   [2] = 169931
   [3] = 169932
   [4] = 169933
how do I get it to sort again from 0,1,2,3 etc?
I tried sort(), ksort(),reset() etcbut it still shows as starting from 1
instead of resorting the keys starting from 0
what function should i lookup/use?
If you're always taking the first element, why not use array_shift?
http://us2.php.net/manual/en/function.array-shift.php
array_shift() shifts the first value of the array off and returns it, 
shortening the array by one element and moving everything down. All 
numerical array keys will be modified to start counting from zero while 
literal keys won't be touched. If array is empty (or is not an array), 
NULL will be returned.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Simple array question, part 2

2005-04-06 Thread Jay Blanchard
[snip]
Nope, array_pop is just deleting the last key/valuei need to reindex
it
without deleteing anything.
[/snip]

Always reply to the list ('reply all') as the individual who answered
you might not be there. Always. I mean it.

You shouldn't just delete an item from an array, it is improper
handling
Thats right, it's not array_pop(), its array_shift()...musta' had a
brain fart and you didn't see the other array functions

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple array question, part 2

2005-04-06 Thread Ryan A
PERFECT!
Thanks mate.
-Ryan

On 8/6/2005 6:47:22 PM, Josip Dzolonga ([EMAIL PROTECTED]) wrote:
 Ryan A wrote:
 
 
 
 what function should i lookup/use?
 
 
 
 Thanks,
 
 Ryan
 
 
 
 This will do the job :
 
 $array = array_values($array);
 
 
 
 Hope this helps,
 
 
 
 --
 
 Josip Dzolonga
 
 http://josip.dotgeek.org
 
 
 
 jdzolonga[at]gmail.com
 
 
 
 --
 
 PHP General Mailing List (http://www.php.net/)
 
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.3 - Release Date: 4/5/2005

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Simple array question, part 2

2005-04-06 Thread Brent Baisley
Just so you know what is happening, the numbers are keys (index) for 
each array element, not the order number. It's the same as if you had 
named the elements themselves. Like this:
['zero']=158
['one']=169926
['two']=169931
...

Or
[0]=158
[12]=169926
[5]=169931
...
Deleting an element won't reorder the names of  the elements since php 
wouldn't know how.

On Apr 6, 2005, at 12:37 PM, Ryan A wrote:
Hey,
I have a $data array like this:
[0] = 158
[1] = 169926
[2] = 169931
[3] = 169932
[4] = 169933
then when i delete the first one ([0] = 158) it becomes like this:
[1] = 169926
[2] = 169931
[3] = 169932
[4] = 169933
how do I get it to sort again from 0,1,2,3 etc?
I tried sort(), ksort(),reset() etcbut it still shows as starting 
from 1
instead of resorting the keys starting from 0

what function should i lookup/use?
Thanks,
Ryan

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.3 - Release Date: 4/5/2005
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Simple array question, part 2

2005-04-06 Thread Ryan A
Nope, array_shift()... is taking off the last one too
Josip sent me the solution:
$array = array_values($array);

Cheers,
Ryan


On 4/6/2005 6:45:40 PM, Jay Blanchard ([EMAIL PROTECTED])
wrote:
 [snip]

 Nope, array_pop is just deleting the last key/valuei need to reindex

 it

 without deleteing anything.

 [/snip]



 Always reply to the list ('reply all') as the individual who answered

 you might not be there. Always. I mean it.



 You
 shouldn't just delete an item from an array, it is improper
 handling
 Thats right, it's
 not array_pop(), its array_shift()...
 musta' had a
 brain fart and you didn't see the other array functions



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.3 - Release Date: 4/5/2005

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php