<?php
/* Function definition:
* 1. The function is 1 One named
* 2. Separate code snippets
* 3. Functions perform specific tasks
* 4. And can be returned to the calling program 1 A value
*
* Advantages of the function:
* 1. Improve program reusability
* 2. Improve program maintainability
* 3. Can improve the development efficiency
* 4. Improve software reliability
* 5. Control the complexity of the program
*
* Declaration of functions
* function The function name (){
*
* }
*
* function The function name ( parameter 1 , the parameter 2 , the parameter ...)
* {
* The body of the function
* }
*
* function The function name ()
* {
* The body of the function ;
* The return value ;
* }
* function The function name ( The list of parameters ...)
* {
* The body of the function ;
* The return value
* }
*
* Note:
* 1. A function must be called to execute and can be called before or after the declaration
* 2. Function names and variables 1 The sample, aaa bbb ccc aaaBbbCcc( The first 1 Words are lowercase, and the first letter of each word is capitalized )
* 3. Functions cannot be renamed when they are declared
* 4. You can change the behavior of a function by passing arguments to it
* Parameter: in the declaration of the function, the declared parameters, parameters are variables, multiple parameters , separate
* Argument: passes the value of the shape parameter when the function is called ( Data can also be variables )
* 5. If no value is returned, it is called a procedure
* 6. Through the use of return Statement returns data
* 7. Function to return The statement ends. Don't write code after the statement , You can also use return End the execution of the function
*
* Function name:
* 1. Call the function and start executing the function
* 2. You can pass data to a function
* 3. The function name is the value returned
*
*
*/
//1 Output table function
function table($tablename,$width,$row,$col)
{
echo '<table border="1" width="'.$width.'"align="center">';
echo '<caption><h1>'.$tablename.'</h1></caption>';
for($i=0;$i<$row;$i++)
{
// Interlaced color change
if($i%2==0)
$bg="#cccccc";
else
$bg="yellow";
echo '<tr bgColor="'.$bg.'">';// Output line
for($j=0;$j<$col;$j++)
{
echo '<td>'.($i*$row+$j).'<function table($tablename,$width,$row,$col)
{
echo '<table border="1" width="'.$width.'"align="center">';
echo '<caption><h1>'.$tablename.'</h1></caption>';
for($i=0;$i<$row;$i++)
{
// Interlaced color change
if($i%2==0)
$bg="#cccccc";
else
$bg="yellow";
echo '<tr bgColor="'.$bg.'">';// Output line
for($j=0;$j<$col;$j++)
{
echo '<td>'.($i*$row+$j).'</td>';
}
echo '</tr>';
}
echo '</table>';
}/td>';
}
echo '</tr>';
}
echo '</table>';
}
table(" The output form ",600,10,10);
table(" The output form 2",300,6,6);
// On the other 1 Type of output
function table2($tablename,$width,$row,$col)
{
$str='<table border="1" width="'.$width.'"align="center">';
$str.= '<caption><h1>'.$tablename.'</h1></caption>';
for($i=0;$i<$row;$i++)
{
// Interlaced color change
if($i%2==0)
$bg="#cccccc";
else
$bg="yellow";
$str.='<tr bgColor="'.$bg.'">';// Output line
for($j=0;$j<$col;$j++)
{
$str.='<td>'.($i*$row+$j).'</td>';
}
$str.='</tr>';
}
$str.='</table>';
return $str;
}
echo table2(" Direct output form ",400,15,15);
?>