RE: [PHP] reindexing an array after unset()
| From: | Ford, Mike [LSS] | Date: | Thu, 09 May 2002 10:52:14 +0000 |
| Subject: | RE: [PHP] reindexing an array after unset() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-96793@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Erik Price [mailto:pricee@hhbrown.com]
> Sent: 08 May 2002 20:23
>
> After using unset() on an array element to remove it, what is
> the best
> way to reindex the array so that I have a nice sequential
> order of 0, 1,
> 2, 3... again? (Otherwise, unset($array[2]) will leave me
> with an array
> that looks like 0, 1, 3...).
I'd try
$arr = array_values($arr);
Reads nicely, anyway!
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211