I was asked this interview question recently:
"Which PHP mechanism allows to use visitor pattern to sort an array?".
I am not sure what mechanism we have in PHP? Can anyone provide an example of its use as well?
My guess is:
In the Visitor pattern, one class calls a function in another class with the current instance of itself. The called class has special functions for each class that can call it.
Accorting to php docs:
uasort — Sort an array with a user-defined comparison function and maintain index association
uasort($collection, array('MyClassName', 'mySortMethod'));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments