PHP - Sort by Array-Value-Length

<?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

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Suche

Neueste Kommentare