简体   繁体   English

如何按降序从数组中单独显示每个值?

[英]How to show each value separately from Array in descending order?

Want to show values separately from an array by writing "Echo".想要通过编写“Echo”来显示与数组分开的值。 Also for each "Echo" code, the values must go in descending order.同样对于每个“Echo”代码,值必须按降序排列为 go。

Here is the Code for Descending values:这是降序值的代码:

<?php
$toplist = array(10, 15, 20, 13, 18, 21, 25);

rsort($toplist);

$length = count($toplist);
for($x = 0; $x < $length; $x++) {
    echo $toplist[$x];
    echo "<br>";
}
?>

And the Output appears together like this:而 Output 一起出现是这样的:

25
21
20
18
15
13
10

But I want all values separately in descending order by writing each "Echo" code. 但是我希望通过编写每个“Echo”代码来分别按降序排列所有值。

For exaples:例如:

   echo $toplist[$x2];

output: 25 output: 25

   echo $toplist[$x3];

output: 21 output: 21

etc. etc...

output: 20 output: 20

 etc. etc...

Once the value is reverse-sorted with rsort , you can access any value in the array like this:使用rsort对值进行反向排序后,您可以像这样访问数组中的任何值:

echo $toplist[0];
echo $toplist[1];
echo $toplist[2];
echo $toplist[3];
echo $toplist[4];
echo $toplist[5];
echo $toplist[6];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM