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 ."
";
?>