What’s the best way in PHP to sort an array of arrays based on array length?
e.g.
$parent[0] = array(0, 0, 0); $parent[2] = array('foo', 'bar', 'b', 'a', 'z'); $parent[1] = array(4, 2); $sorted = sort_by_length($parent) $sorted[0] = array(4, 2); $sorted[1] = array(0, 0, 0); $sorted[2] = array('foo', 'bar', 'b', 'a', 'z');
This will work:
Note that this function will preserve the numerical keys. If you want to reset the keys, wrap it in a call to array_values().