detlevski Posted May 27, 2014 Share Posted May 27, 2014 Change the sorting algorithm based on the desired sort order: if ($this->_order == 'ascending') { uasort($list, array($this, ➝ 'ascSort')); } else { uasort($list, array($this, ➝ 'descSort')); } The second argument to the uasort() function should be the name of the function to use for the comparison. Because that function—ascSort() or descSort()—is defined as a method in this current object, you can use this construct to reference it: array($this, 'methodName'). In chapter 7 I don't get the construct above here in BOLD, did I miss something ? Why not use uasort($list, 'ascSort'); 1 Link to comment Share on other sites More sharing options...
Larry Posted May 31, 2014 Share Posted May 31, 2014 Sorry for the confusion. You need to provide a function reference to uasort(). If you just provided "ascSort" there, you'd get an error because there's no "ascSort" function in PHP. That method exists, but only within a class or object. So to tell uasort() about the right method to use, you have to provide the object instance and the method name, doing so using array(). Let me know if it's still unclear. Link to comment Share on other sites More sharing options...
detlevski Posted June 16, 2014 Author Share Posted June 16, 2014 Hi Larry, thanks for your reply, that makes sense and playin g with the file made it already clear. By the way, the book is great for grasping the basics of OOP. Link to comment Share on other sites More sharing options...
Larry Posted June 16, 2014 Share Posted June 16, 2014 Glad it was helpful and thanks for the nice words on the book. Happy to hear that! Link to comment Share on other sites More sharing options...
Recommended Posts