how to put this here in ascending order? [duplicate]

0
<?php
  $var = 5;
  for ($i = 0; $i <= $var-1; $i++) {
    $new_data = array($i => $count[$i]["rank"]);
    foreach ($new_data as $i => $key) {
      print(var_export($key).",");
    }
  }
?>

It returns this: 87,41,88,32,26,26,48,16,0,34,46,135,11,38,52,33

How to return this in ascending order? or in numerical order?

    
asked by anonymous 18.02.2018 / 14:43

2 answers

2

Put this before foreach

sort($new_data, SORT_NUMERIC); 

Reference (PHP4, 5 and 7): PHP Sort

    
18.02.2018 / 14:50
0

In the documentation below you have several options for doing this, but one of them is asort

<?php
$frutas = array("d" => "limao", "a" => "laranja", "b" => "banana", "c" => "melancia");
asort($frutas);
foreach( $frutas as $chave => $valor ){
    echo "$chave = $valor\n";
}
?>

Go to print:

b = banana
a = laranja
d = limao
c = melancia

Your is numeric array, but should serve

Official Documentation: link

    
18.02.2018 / 16:14