Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to flip the variables?

Posted on 2009-04-20
5
Medium Priority
?
506 Views
Last Modified: 2012-05-06
How to flip an array or variable values in descendinf order? is there any function for this. please don't take it with database.
0
Comment
Question by:designersx
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:xSuperioRx
ID: 24191129
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
 

Author Comment

by:designersx
ID: 24191192
this link does not work.
0
 
LVL 2

Accepted Solution

by:
xSuperioRx earned 300 total points
ID: 24191202
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
 
LVL 11

Expert Comment

by:spoxox
ID: 24195650
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
 

Author Comment

by:designersx
ID: 24196907
no sir this question was totally different from the other question.

thanks for the solution.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question