can any one help me how to get the sorting of the numbers;
num1 = 1
num2 = 1
num3 = 3
num4 = 5
$values = array($_POS开发者_高级运维T["num1"] => 1, $_POST["num2"] => 2,$_POST["num3"] => 3,$_POST["num4"] =>4);
asort($values);
foreach($values as $key => $val){
echo "<br>$key = $val<br>";
}
The num1 is not printed.. and i got an out put of
1 = 2
3 = 3
4 = 4
how can i got the output complete like this?
1 = 1 | 1 = 2 | 3 = 3 | 4 = 4
You have the key => value pair the wrong way round in your array, hence why your key for 1 gets overwritten.
Try replacing your $values = ... line with this:
$values = array(1 => $_POST["num1"], 2 => $_POST["num2"], 3 => $_POST["num3"], 4 => $_POST["num4"]);
精彩评论