Why doesn’t usort() sort the array?
if ( is_array( $tables ) ) {
usort( $tables, 'sort' );
} else {
echo "no array";
}
I always get this warning:
sort() expects parameter 1 to be array, string given
so php thinks its an array but usort() not
heres the sort function:
function sort( $a, $b ) {
return strlen( $b ) - strlen( $a );
}
Note the error says
sort() expects, notusort() expects. That’s because PHP is interpreting the callback tousortas the built-insort()method (which expects the 1st parameter to be an array), not yoursort()method.Try renaming your method to something else, like
my_sort.