时间:2021-07-01 10:21:17 帮助过:7人阅读
php
function func( $arg_1 , $arg_2 , , $arg_n )
{
echo " Example function.\n " ;
return $retval ;
}
?>
1 php
2 $isRequired = true ;
3 if ( $isRequired )
4 {
5 function func( $op1 , $op2 )
6 {
7 return $op1 + $op2 ;
8 }
9 }
10 if ( $isRequired )
11 echo " func(1,3)= " . func( 1 , 3 );
12
13 function helloWorld()
14 {
15 return " Hello,world " ;
16 }
17 echo '
Call function helloWorld(): ' . helloWorld();
18 ?>
func( 1 , 3 ) = 4
Call function helloWorld() : Hello , world
1 php
2 function func()
3 {
4 function subfunc()
5 {
6 echo " I don't exist until func() is called.\n " ;
7 echo " I have alrady made " ;
8 }
9 }
10
11 /* We can't call subfunc() yet
12 since it doesn't exist. */
13
14 func();
15
16 /* Now we can call subfunc(),
17 func()'s processesing has
18 made it accessable. */
19
20 subfunc();
21
22 ?>
I don ' t exist until func() is called. I have alrady made
php
function MakeComputerBrand( $brand = " IBM " )
{
return " Making " . $brand . " computer now.
" ;
}
echo MakeComputerBrand();
echo MakeComputerBrand( " DELL " );
echo MakeComputerBrand( " HP " );
echo MakeComputerBrand( " Lenevo " );
?>
Making IBM computer now .
Making DELL computer now .
Making HP computer now .
Making Lenevo computer now .
php
function small_numbers()
{
return array ( 0 , 1 , 2 );
}
list ( $zero , $one , $two ) = small_numbers();
?>