Rsort() Does not work properly..
Posted: Thu Sep 10, 2009 5:33 am
So my original code is
It was my homework and the task is to display an array and reverse the order of the array after the "Reverse" button is clicked.
My lecturer said the whole code should be in a one single php page.
The first click of reverse button successfully reversed the order of array but then the following does not..
Is there any problem within the php script?
Thanks for helping
Code: Select all
<?php
$nut=array('Bao','IM','Joel','Sacrifire','Serge','Skychin','Skylooker','Soulchild');
if(isset($_POST['reverse']) && $nut[0]=='Soulchild'):
rsort($nut);
elseif(isset($_POST['reverse']) && $nut[0]=='Bao'):
rsort($nut);
endif;
//show word
for($x=0;$x<8;$x++)
{
echo $nut[$x]." ";
if ($x%2!=0)
{
echo "</br>";
}
}
print_r($nut);
?>
<form action="array.php" method="post">
<input type="submit" name="reverse" value="Reverse!!">
</form>
My lecturer said the whole code should be in a one single php page.
The first click of reverse button successfully reversed the order of array but then the following does not..
Is there any problem within the php script?
Thanks for helping