Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would sort fail?

Tags:

php

sorting

I'm writing a library routine, which among other things will do some rather complex sorting of nested arrays.

I see from the documentation that all the array sort function (including the ones using built-in comparators) can return false on failure - but when would this ever be the case???

like image 278
symcbean Avatar asked Mar 18 '11 16:03

symcbean


Video Answer


1 Answers

It would fail when the variable you send to the function is NOT an array
Example:

asort('Hello');//fails
asort(array(1,2,35,7,2,8,3));//true
like image 157
Naftali Avatar answered Oct 02 '22 21:10

Naftali