PHP - Sort by Array-Value-Length

Submitted by Gast (nicht überprüft) on Mi, 07/19/2017 - 23:39

<?php

$myarray = [ "aa", "bbb", "c", "dddddd", "eeee"];

  usort($myarray, 'sortbylength' );

 function sortbylength($a,$b){
    return strlen($b)-strlen($a);
}

 echo "<pre>";
 print_r( $myarray );

?>

 

Output:

Array (

  [0] => dddddd

  [1] => eeee

  [2] => bbb

  [3] => aa

  [4] => c

)

Neuen Kommentar schreiben

Bild-CAPTCHA