<?php
$myarray = explode(" ", "this is a bunch of words");
usort($myarray, function($a, $b) {
return strlen($b) - strlen($a);
});
print_r($myarray);
/*function sortByLength($a,$b){
return strlen($b)-strlen($a);
}
$array = array("bbbbb", "dog", "cat", "aaa", "aaaa");
$sorted = usort($array,'sortByLength');
var_dump($sorted);*/
/*$priorities = array(5, 8, 3, 7, 3);
usort($priorities, function($a, $b)
{
if ($a == $b)
{
echo "a ($a) is same priority as b ($b), keeping the same\n";
return 0;
}
else if ($a > $b)
{
echo "a ($a) is higher priority than b ($b), moving b down array\n";
return -1;
}
else {
echo "b ($b) is higher priority than a ($a), moving b up array\n";
return 1;
}
});
echo "Sorted priorities:\n";
var_dump($priorities);*/
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Array
(
[0] => bunch
[1] => words
[2] => this
[3] => is
[4] => of
[5] => a
)
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
- Array
(
[0] => bunch
[1] => words
[2] => this
[3] => of
[4] => is
[5] => a
)
preferences:
266.37 ms | 402 KiB | 376 Q