PHP recursion error I wrote a class Sort. php. the code for fast sorting of the methods in it is as follows: & lt ;? Phpclass & nbsp; Sort {& nbsp; public & nbsp; function & nbsp; quickSort ($ arr) {$ countcount ($ arr); if ($ cou PHP recursive error
I wrote a class Sort. php, and the code for implementing the fast sorting of the methods in it is as follows:
Class Sort {
Public function quickSort ($ arr ){
$ Count = count ($ arr );
If ($ count <= 1)
Return $ arr;
$ Key = $ arr [0];
$ Left_arr = array ();
$ Right_arr = array ();
For ($ I = 1; $ I <$ count; $ I ++ ){
If ($ arr [$ I] <= $ key ){
$ Left_arr [] = $ arr [$ I];
} Else {
$ Right_arr [] = $ arr [$ I];
}
}
$ Left_arr = quickSort ($ left_arr );
$ Right_arr = quickSort ($ right_arr );
Return array_merge ($ left_arr, array ($ key), $ right_arr );
}
}
?>
Then I wrote a test, sortTest. php. the code is as follows:
Require ('sort. php ');
$ Array = array (12, 15, 9, 20, 6, 31, 24 );
$ Sort = new Sort ();
$ Arr = $ sort-> quickSort ($ array );
$ Arr = quickSort ($ array );
Print_r ($ arr );
?>
When I run this test file, the following error is returned:
Fatal error: Call to undefined function quickSort () in D: \ WWW \ PHPDemo \ suanfa \ Sort. php on line 75
I called an undefined method, but when I put this method in sortTest. php, there is no problem. Thank you very much for explaining this ~
------ Solution --------------------
Class methods are scoped.
$ Left_arr = $ this-> quickSort ($ left_arr );
$ Right_arr = $ this-> quickSort ($ right_arr );
------ Solution --------------------
Khan, #1 the red part has long marked the wrong part with you. The reply is not careful ..