PHP sort array of associative arrays by element size / string size -
is there way sort array of associative arrays length of 1 of elements? trying order arrays largest smallest description length.
$some_array = []; $some_array[0] = ['name'=>'a name','description'=>'a description']; $some_array[1] = ['name'=>'a name1','description'=>'a description 1']; $some_array[2] = ['name'=>'a name2','description'=>'a description 2 third array element']; $some_array[3] = ['name'=>'a name3','description'=>'a description three'];
with above example $some_array[2]
should come first followed 3
1
0
.
php >= 5.5.0 needed array_column
:
array_multisort(array_map('strlen', array_column($some_array, 'description')), sort_desc, $some_array);
Comments
Post a Comment