Reply to Re: [PHP] Simple array question, part 2

Your name:

Reply:


Posted by Philip Hallstrom on 04/06/05 19:33

> 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() etc....but 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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация