Sort array by amount of keys.
<?php
$key_a='a';
$key_b='b';
$key_c='c';
$myarray[$key_a][]='1';
$myarray[$key_a][]='2';
$myarray[$key_a][]='3';
$myarray[$key_b][]='2';
$myarray[$key_b][]='2';
$myarray[$key_c][]='a';
?>
I want to end up with the following array:
<?php
$myarray[$key_a][]='1';
$myarray[$key_a][]='2';
$myarray[$key_a][]='3'; //$key_a with 3 values
$myarray[$key_b][]='2';
$myarray[$key_b][]='2'; //$key_b with 2 values
$myarray[$key_c][]='a'; //$key_c with 1 value
?>
A custom function is needed to get the new array sorted by highest count of values?
Also – if there is match in the amount of total keys/values I’d like to work with $key_a, $key_b and $key_c to sort these in between –
in this case if $key_b array had 3 values, $key_a declared as ‘a’ would come first in the new array if sorting alpha. But it’d be numeric instead, if two sub arrays have the same amount of keys then these would preferably be sorted numeric by key.
http://php.net/uksort