Re: Re: array - change elements position
| From: | Pushkar Pradhan | Date: | Thu, 25 Apr 2002 20:37:26 +0000 |
| Subject: | Re: Re: array - change elements position | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94654@lists.php.net to get a copy of this message | ||
Have you thought about swapping the elements, it's quite simple, I don't
know about more complicated methods using pointers
here's the code:
$layer is the array -
$currPos = array_search($HTTP_POST_VARS["selLayer"], $layer);
$temp = $layer[$currPos];
$layer[$currPos] = $layer[$currPos-1];
$layer[$currPos-1] = $temp;
> My example wasn't good.
>
> I have a array of objects and want change its positions.
>
> $array = (obj2, obj1, obj3) --> $array = (obj1, obj2, obj3).
>
> Like TStringList.Exchange in Delphi.
>
> Sort() don't work in this case, because I want sort based in a attribute of
> the object.
>
> Evandro
>
>
> "Evandro Sestrem" <evandro@blueone.com.br> escreveu na mensagem
> news:20020425193419.21226.qmail@pb1.pair.com...
> > Hello,
> >
> > Has a automatic way to change the position from 2 elements of a array
> > without use a aux variable?
> > Like that:
> > A = (1,3,2) --> A = (1, 2, 3)
> >
> > Thanks,
> >
> > Evandro
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
-Pushkar S. Pradhan