Re: a quick question about array keys
| From: | Ashley Sheridan | Date: | Tue, 31 Aug 2010 15:59:09 +0000 |
| Subject: | Re: a quick question about array keys | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307777@lists.php.net to get a copy of this message | ||
On Tue, 2010-08-31 at 16:58 +0100, Richard Quadling wrote:
> On 31 August 2010 16:45, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:
> > There are two ways I see to do it. You can iterate the array and create
> > a copy, assigning elements dynamic values:
> >
> > $new_array = array();
> > foreach($array as $a)
> > {
> > $new_array[] = $a;
> > }
> >
> > or use a sorting function on it that doesn't preserve the keys (as in
> > your example all the values in the array were in numerical order.
> >
> > $new_array = sort($array);
>
> sort() operates in the array. It does not return a new array, just a
> bool to indicate success or not.
>
> http://docs.php.net/sort
>
>
>
Ah, my bad!
Thanks,
Ash
http://www.ashleysheridan.co.uk