PHP recursive error. how can this problem be solved?

Source: Internet
Author: User
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 ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.