PHP can declare a function in the function to call internal functions to help external functions complete some sub-functions. The code is as follows:
/*
* 1. internal function: PHP can declare the function inside the function.
* The purpose is to call the function internally.
* Used to help external functions complete some sub-functions
*
* 2. recursive functions: Call your own function name within yourself.
*
* 3. reuse functions
*
* Require: used for static inclusion
* Include: used for dynamic inclusion
* Require_once: used for static inclusion only once
* Include_once: used for dynamic inclusion, only once
*
* 4. use of some system functions
* Resource = opendir ("directory name ")
* Readdir (resource)
*
*
*/
// Internal functions
Function score ($ php, $ java, $ dotnet)
{
Function php ($ php)
{
If ($ php> 60)
Return "pass ";
Else
Return "fail ";
}
Function java ($ java)
{
If ($ java> 60)
Return "pass ";
Else
Return "fail ";
}
Function dotnet ($ dotnet)
{
If ($ dotnet> 60)
Return "pass ";
Else
Return "fail ";
}
$ Total = $ php + $ java + $ dotnet;
$ Agv = $ total/3;
Echo "your php score is {$ php},". php ($ php )."
";
Echo "your java score is {$ java},". java ($ java )."
";
Echo "your dotnet score is {$ dotnet},". dotnet ($ dotnet )."
";
Echo "your total score is: {$ total}
";
Echo "your average score is: {$ agv}
";
}
Score (50, 90, 70 );
// Recursive function
Function demo ($ num)
{
Echo $ num ."
";
If ($ num> 0)
Demo ($ num-1 );
Else
Echo "--------------------------------
";
Echo $ num ."
";
}
Demo (10 );
Function total ($ dirname, & $ dirnum, & $ filename)
{
$ Dir = opendir ($ dirname );
Readdir ($ dir )."
";
Readdir ($ dir )."
";
While ($ filename = readdir ($ dir ))
{
$ Newfile = $ dirname. "/". $ filename;
Echo $ filename ."
";
If (is_dir ($ filename
}
}
$ Dirnum = 0;
$ Filenum = 0;
Total ("c:/windows", $ dirnum, $ filenum );
Echo "total number of directories:". $ dirnum ."
";
Echo "total number of files:". $ filenum ."
";
?>
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