<?php
echo "<html>
<head>
<title>QUIZ-FINALS</title>
</head>
<body background=fatcat.jpg>
<form method=post>
<table border=0>
<tr><td colspan=3><b>Enter eight Score:</b><br></td></tr>
<tr><td><input type=text name=1></td><td><input type=text name=2></td><td><input type=text name=3></td><td><input type=text name=4></td></tr>
<tr><td><input type=text name=5></td><td><input type=text name=6></td><td><input type=text name=7></td><td><input type=text name=8></td></tr>
<tr><td colspan=4><input type=hidden name=h value=true> <center><input type=submit value=Compute></center></td></tr>
</form></table>
<br>";

if($_POST['h']==true)
{
$n[0]=$_POST['1'];
$n[1]=$_POST['2'];
$n[2]=$_POST['3'];
$n[3]=$_POST['4'];
$n[4]=$_POST['5'];
$n[5]=$_POST['6'];
$n[6]=$_POST['7'];
$n[7]=$_POST['8'];

$h=$n[0];
for($x=0;$x<8;$x++)
if($h<$n[$x])
$h=$n[$x];
echo "<b>The Highest Score:</b> $h<br><br>";

$l=$n[0];
for($x=0;$x<8;$x++)
if($l>$n[$x])
$l=$n[$x];
echo "<b>The Lowest Score:</b> $l<br><br>";

echo "The Score and Their Differences from the highest are:<br>";

for($x=0;$x<8;$x++)
{
echo $n[$x];
echo " off by ";
echo $h-$n[$x];
echo "<br>";
}

ECHO "the arrangment of the numbers";


echo "<br>Try Another?<br>";
echo "<a href='aldrich_array.php'>Yes</a>";
echo " <a href='about:blank'>No</a>";
}

echo "</body>
</html>";
?>

my problem here is how can I code the sorted array
example is this

my problem starts here:

I input the numbers 10 20 30 40 54 8 0 1
the ascending order is: 0 1 8 10 20 30 40 54
the descending order is: 54 40 30 20 10 8 1 0

http://php.net/manual/en/function.asort.php

Please help me right now please..... i add this code but the output was wrong.... this is the updated code:

<?php
echo "<html>
<head>
<title>QUIZ-FINALS</title>
</head>
<body background=fatcat.jpg>
<form method=post>
<table border=0>
<tr><td colspan=3><b>Enter eight Score:</b><br></td></tr>
<tr><td><input type=text name=1></td><td><input type=text name=2></td><td><input type=text name=3></td><td><input type=text name=4></td></tr>
<tr><td><input type=text name=5></td><td><input type=text name=6></td><td><input type=text name=7></td><td><input type=text name=8></td></tr>
<tr><td colspan=4><input type=hidden name=h value=true> <center><input type=submit value=Compute></center></td></tr>
</form></table>
<br>";

if($_POST['h']==true)
{
$n[0]=$_POST['1'];
$n[1]=$_POST['2'];
$n[2]=$_POST['3'];
$n[3]=$_POST['4'];
$n[4]=$_POST['5'];
$n[5]=$_POST['6'];
$n[6]=$_POST['7'];
$n[7]=$_POST['8'];

$h=$n[0];
for($x=0;$x<8;$x++)
if($h<$n[$x])
$h=$n[$x];
echo "<b>The Highest Score:</b> $h<br><br>";

$l=$n[0];
for($x=0;$x<8;$x++)
if($l>$n[$x])
$l=$n[$x];
echo "<b>The Lowest Score:</b> $l<br><br>";

echo "The Score and Their Differences from the highest are:<br>";

for($x=0;$x<8;$x++)
{
echo $n[$x];
echo " off by ";
echo $h-$n[$x];
echo "<br>";
}
$h=$n[0];
for($x=0;$x<8;$x++){
while($h<$n[$x])
$h=$n[$x];
echo "$h ";
}
$l=$n[0];
for($x=0;$x<8;$x++){
while($l>$n[$x])
echo "$l ";
}
ECHO "the arrangment of the numbers";


echo "<br>Try Another?<br>";
echo "<a href='aldrich_array.php'>Yes</a>";
echo " <a href='about:blank'>No</a>";
}

echo "</body>
</html>";
?>

I need the code for descending and ascending order please

<?php
echo "<html>
<head>
<title>QUIZ-FINALS</title>
</head>
<body background=fatcat.jpg>
<form method=post>
<table border=0>
<tr><td colspan=3><b>Enter eight Score:</b><br></td></tr>
<tr><td><input type=text name=1></td><td><input type=text name=2></td><td><input type=text name=3></td><td><input type=text name=4></td></tr>
<tr><td><input type=text name=5></td><td><input type=text name=6></td><td><input type=text name=7></td><td><input type=text name=8></td></tr>
<tr><td colspan=4><input type=hidden name=h value=true> <center><input type=submit value=Compute></center></td></tr>
</form></table>
<br>";

if($_POST['h']==true)
{
$n[0]=$_POST['1'];
$n[1]=$_POST['2'];
$n[2]=$_POST['3'];
$n[3]=$_POST['4'];
$n[4]=$_POST['5'];
$n[5]=$_POST['6'];
$n[6]=$_POST['7'];
$n[7]=$_POST['8'];

$h=$n[0];
for($x=0;$x<8;$x++)
if($h<$n[$x])
$h=$n[$x];
echo "<b>The Highest Score:</b> $h<br><br>";

$l=$n[0];
for($x=0;$x<8;$x++)
if($l>$n[$x])
$l=$n[$x];
echo "<b>The Lowest Score:</b> $l<br><br>";

echo "The Score and Their Differences from the highest are:<br>";

for($x=0;$x<8;$x++)
{
echo $n[$x];
echo " off by ";
echo $h-$n[$x];
echo "<br>";
}

ECHO "the arrangment of the numbers";


echo "<br>Try Another?<br>";
echo "<a href='aldrich_array.php'>Yes</a>";
echo " <a href='about:blank'>No</a>";
}

echo "</body>
</html>";
?>

my problem here is how can I code the sorted array
example is this

my problem starts here:

I input the numbers 10 20 30 40 54 8 0 1
the ascending order is: 0 1 8 10 20 30 40 54
the descending order is: 54 40 30 20 10 8 1 0

there are ksort(),asort,usort(),etc functions available in php,u do not have to manually sort an array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.