Jump to content

[SOLVED] placing in order question


jamsearch

Recommended Posts

Hope someone can help me.

 

I am writing a program using php and mysql.

 

I have ten variables with number values set in each one. None of these numbers will ever equal the same value to one another.

(all will always have different values to one another)

 

for example:

 

$D01 = 444

$D02 = 474

$D03 = 644

$D04 = 447

$D05 = 488

$D06 = 554

$D07 = 1

$D08 = 44

$D09 = 1444

$D10 = 24

 

Here's the problem. I want to be able to output the variables in order from high to low. I have no problem figuring out the highest number or the lowest number but I'm baffled how to get the rest in line. I've been trying for days and nothing I come up with works. Is there a way of doing this? If I could use GOTO there would be no problem but without it ,it seems there would have to be thousands of lines of code to get the result I'm after. Any help would be greatly appreciated. Thanks. ???

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Yeah, arrays are the way to go for sorting. You could easily transform you variables to an array like:

 

<?php
error_reporting(E_ALL);
$D01 = 444; 
$D02 = 474;
$D03 = 644; 
$D04 = 447; 
$D05 = 488; 
$D06 = 554; 
$D07 = 1; 
$D08 = 44; 
$D09 = 1444; 
$D10 = 24; 
$D = array();
for($i=1;$i<=10;$i++){
$D[$i] = ${'D'.str_pad($i,2,0,STR_PAD_LEFT)};
}
rsort($D);
echo '<pre>'.print_r($D,1).'</pre>';
?>

 

Though it would be better to put them in an array to start with.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.