Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

place into array and sort 1

Status
Not open for further replies.

krappleby

Programmer
Jul 25, 2006
25
GB
hi all,

wonder if you can help me..

i have 9 variables, labelled

ball1, ball2, ball3, ball4, ball5, ball6, ball7, ball8, ball9

now. im looking to sort them in order of the value of each variable.. im thinking the best way to do this would be to put them all into an array and have the array sort them.. is this possible. and if so how do you do it..

or is there an easier way to do this.

ps.. each variable will contain a number between 1 and 100
 
hi feherke

thanks for the comment, yes that is what i thought would be the best option, but question is.. how do i sort them to ascending order?

is there a command within the array function that will do this..

cheers

keith
 
hi this is and is not working..

at the moment i have all the values in an array called $balllist

i ahve used asort, and printed for each value in the array..

This works..

but when i come to echo $balllist[0] its not the lowest ball..

so its not sorting as i requre.. i need to get it to sort all the balls, into order, so that i can run through the [0][1][2] and it iwll be in order..

cheers

any ideas.. thanks for the help
 
Code:
$array = array('ball1', 'ball2', 'ball3', 'ball4', 'ball5', 'ball6', 'ball7', 'ball8', 'ball9');
$balls = compact($array); //assemble into array
$sortedBalls = sort($balls, SORT_NUMERIC);
print_r($sortedBalls);

as feherke says, it would be better to use an array from scratch than create one out of disparate variables.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top