开发者

PHP array sorting cant get the correct output

开发者 https://www.devze.com 2023-04-09 22:48 出处:网络
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\"] =&

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"]);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号