Would it not just be easier to randomise 3 numbers, place them in an array, sort the array and echo them out?
Main Topics
Browse All TopicsIn college, the teacher send me a php homework.
rand three numbers, and list all numbers from the highest sorted to the lowest sortted.
i done with 2, but no with three.
$a=rand(1,100);
$b=rand(1,100);
if($a>$b) {
while($a>$b) {
printf("$a<br>");
$a--;
} }
else if($b>$a) {
while($b>$a) {
printf("$b<br>");
$b--;
} }
but i cant do with three, cause the 'if' doesnt work with for exemple: if($a>$b>$c)
why the if() dowsnt work with thress comparasions?
tx.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The code block for the if statement of:
if($a>$b || $b>$c)
Would execute if $a is greater than $b and/or $b is greater than $c. Since either individual expression could be true and it will enter the if statement code block, I don't think you gather any valuable information from that if statement structure.
As elpasi eluded to, there may be easier ways to accomplish this depending on the assignment, so you may want to look into array sorting.
>> i can do
if($a>$b || $b>$c) ??????????? <<
That is a valid if statement. You will still need to do work to get your homework answer but the if above will work in PHP. That is the correct method to use when you want if to look at 2 conditions. Each one needs to be able to stand on its own (e.g. "if ($a>$b)" and "if ($b>$c)") and then you provide the operator to show the relationship (in the example above you used or).
I hope this helps clear up the principle (without breaking any rules). :) Good luck on the assignment.
bol
You can learn more about the logical operators here:
http://us.php.net/manual/e
I'm glad I could help. I'm a little surprised you didn't choose to split this with other experts too. Let me know if you meant to do that and want to correct it. Otherwise you might want to post a comment to explain why you closed it the way you did. It seems to me that others helped with this too. :)
Thanks for the grade, the points and the fun question.
bol
Business Accounts
Answer for Membership
by: MacAnthonyPosted on 2007-09-18 at 09:29:48ID: 19914381
Because $a>$b>$c isn't a valid expression and the if statement takes an expression (something that evaluates to true or false). The expression $a > $b > $c does not evaluate correctly as strictly true or false in php.
n/language .control- s tructures. php#contro l-structur es.if
http://us.php.net/manual/e
I won't do your homework for you, but I will be more than help you try and understand the assignment.