How to display data in descending order?

Asked

Viewed 770 times

1

I would like to know how I can display the data on descending order across the field score, in that code he’s displaying the smaller for Mayr, and I would like to exhibit the greater for the lesser:

Observem a print: http://i.imgur.com/7MTI5WR.jpg


<?php 


        $pasta = "C:\Users\Vinicius\Desktop\Vinicius\SS Oficial by Vinicius\scriptfiles\Scores"; 
        $classificar = "Score";  

        $jogadores= -1; 
        $dadosjogador = array(); 
        $handlepasta = opendir($pasta); 


        while(($nickname  = readdir($handlepasta)) !== false) { 
                if(($nickname !=".") && ($nickname  !="..") && ($nickname != "index.htm") && ($nickname !="info")) { 
            $jogadores++; 
                        $contaaberta    = parse_ini_file($pasta ."/". $nickname); 
                        $nickname      = substr($nickname, 0,strlen($nickname)-4); 
                        $dadosjogador[$jogadores] =  array($contaaberta[$classificar] ,$nickname ); 
                } 
        } 



        array_multisort ($dadosjogador, $dadosjogador); 



        foreach ($dadosjogador as $jogador_atual) { 
                echo "<b>Jogador</b>:  ".$jogador_atual[1]."    |    <b>Score</b>:  ".$jogador_atual[0]."  <br>"; 
        } 
?>
  • 1

    put this as an answer! and not editing the question! ie, this is part of an answer!

2 answers

2

Solution:

array_multisort ($dadosjogador, SORT_DESC); 

0

In this specific case usort with a function would also solve:

usort($array, function($a,$b){
    return $b[0] > $a[0];
});

being $b[0] and $a[0] is the position of the values, then having the option to place the column that should be ordered.

Browser other questions tagged

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