How do you put this in the ascending order?

Asked

Viewed 719 times

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).",");
    }
  }
?>

he returns it: 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?

  • What have you tried?

  • Instead of polluting the site with repeated questions, read the comments of the original question and follow the tips given.

  • Willian, all right, I believe because you’re new to the site you’re having difficulties, but one thing about the questions, you don’t have to ask the same question over and over again, just ask once, so someone can indicate a duplicate that will answer your question or even an answer. As you have already asked a similar question (which here is called duplicate) this will surely be closed although now has an answer that can help you.

2 answers

2

0

In the documentation below you have several options to do 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";
}
?>

Will print:

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

Yours is a numeric array, but it should serve

Documentación Oficial: https://secure.php.net/manual/en/array.sorting.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.