How to flip the variables?

How to flip an array or variable values in descendinf order? is there any function for this. please don't take it with database.
designersxAsked:
Who is Participating?
 
xSuperioRxCommented:
Works for me, ill paste the content here then :)

Hope this does what your looking for
The output of this PHP code is:
 
Alfred
Chandni
Deepak
Joshua
Robert
Sadiq
Teresa
Vladimir
 
You can see that the names have been alphabetically sorted in the ascending order. To sort of the names in descending order, we change the program like this:
 
<?php
 
$narray[0]="Alfred";
$narray[1]="Robert";
$narray[2]="Deepak";
$narray[3]="Teresa";
$narray[4]="Joshua";
$narray[5]="Chandni";
$narray[6]="Sadiq";
$narray[7]="Vladimir";
 
rsort($narray);
 
for($i=0; $i<8; $i++)
{
print $narray[$i] . "<br />";
}
 
?>
 
Now the output is:
 
Vladimir
Teresa
Sadiq
Robert
Joshua
Deepak
Chandni
Alfred

Open in new window

0
 
xSuperioRxCommented:
If you mean the way they are located in the array then this should help:

http://www.developertutorials.com/tutorials/php/sorting-array-php-051114/page1.html
0
 
designersxAuthor Commented:
this link does not work.
0
 
spoxoxCommented:
In your other post (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24333870.html) it looked like you wanted the keys sorted, so I guess this is a different question. If so, it has been answered above.

If you want the keys sorted too, and if this is the same question as your other post, you should know that it's against policy to repost the same question after abandoning the first version. I mention this as you seem fairly new to EE. Please forgive me if I misunderstood.

(I posted an answer for reverse sorting the keys as well under the other heading.)

If you need guidance on asking questions or accepting answers, just ask. There are many options for assistance.

Best of luck!
0
 
designersxAuthor Commented:
no sir this question was totally different from the other question.

thanks for the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.