<?php
/*-----------------------------函数表格------------------------------------------*/
header("Content-Type:text/html;charset=utf-8");
function table($row,$col,$color){
echo "<table border=1 width='700px' align=center>";
echo"<caption><h1>函数表格</h1></caption>";
$num1=0;
while($num1<$row){
if($num1%2==0){
$bg = $color;
}else{
$bg = 'orange';
}
echo "<tr bgColor='$bg'>";
$num2=0;
while($num2<$col){
echo "<td>{$num2}</td>";
$num2++;
}
echo "</tr>";
$num1++;
}
echo "</table>";
}
echo table(3,2,'lightgreen');
echo table(5,4,'pink');
echo table(9,5,'lightblue');
echo table(4,4,'lightred');
echo "<br/>";
echo "<hr/>";
/*-----------------------------for循环99乘法表------------------------------------------*/
echo"<table align=center width='500px'>";
echo"<caption><h1>for循环99乘法表</h1></caption>";
for($i=1;$i<10;$i++){
echo "<tr>";
for($j=1;$j<=$i;$j++){
echo "<td>$i"."x"."$j"."=".$i*$j."</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<br/>";
echo "<hr/>";
/*--------------------------------do--while例子-------------------------------------*/
$num = 0;
do{
echo $num.'<br/>';
$num++;
}while($num<10);
echo "<br/>";
echo "<hr/>";
/*----------------------for--循环--小例子---------------------------------------------*/
for($i=0;$i<10;$i++){
echo "$i<br/>";
}
echo '<br/>';
for($i=9;$i>=0;$i--){
echo "$i<br/>";
}
echo "<br/>";
echo "<hr/>";
/*---------------------------全局变量---------------------------------------------------------*/
$var=10;
function test(){
echo $GLOBALS['var'];
}
test();
echo "<br/>";
echo "<hr/>";
/*-----------------------静态函数static-------------------------------------------------------------*/
function demo(){
static $a=10;
$a++;
echo $a."<br/>";
}
demo();
demo();
demo();
echo "<br/>";
echo "<hr/>";
/*-----------------------变量函数----------------------------------------------------*/
function A($a,$b){
return $a*$b;
}
function B($a,$b){
return $a+$b;
}
function C($a,$b){
return $a/$b;
}
$var='A';
echo "function A()=".$var(5,5);
echo "<br/>";
$var='B';
echo "function B()=".$var(5,5);
echo "<br/>";
$var='C';
echo "function C()=".$var(5,5);
echo "<br/>";
echo "<hr/>";
/*-----------------------------//函数的分类--------------------------------------------*/
/*
$file= 'e:/1.txt';
echo copy($file,'e:/1.txt.bak');
//移动文件
$new_file = 'F:/1.txt.bak';
echo rename($file,$new_file);
*/
/*-----------------------------//倒序输出数组--------------------------------------------*/
$arr=array(1,2,3,4,5,6);
arsort($arr);
print_r($arr);
echo "<br/>";
echo "<hr/>";
/*-----------------------------//筛查数据出入--------------------------------------------*/
$arr1 = array(1,2,3,4,5,6,7);
$arr2 = array(1,2,3,4,6);
$arr3 = array(0,2,3);
$result=array_diff($arr1,$arr2,$arr3);
var_dump( $result);
echo "<br/>";
echo "<hr/>";
/*-----------------------------//求不限制参数值和--------------------------------------------*/
function dome(){
$args=func_get_args();//过滤数组类型中各参数信息传入变量args;
$sum=0;
for($i=0;$i<count($args);$i++){//将过滤后的参数信息用count遍历出数量
$sum+=$args[$i];
}
echo $sum;
}
echo dome(50,2,33,25,66,2,90,-300,5);
09-17 demo code
最新推荐文章于 2024-02-22 13:37:32 发布