代码
<?php
header("Content-type: text/html; charset=utf-8"); //输出中文编码
/*
function fun_name($str1,$str2,$strn){
fun_body;
}
说明:
function:为声明自定义函数时必须使用到的关键字;
fun_name:自定义函数的名称;
$str1....$strn:函数参数;
fun_body:自定义函数主体,是功能实现部分;
*/
//例一:
function example($num){
echo "$num*$num = ".$num*$num."</br>";
}
echo "例一:</br>";
example(10);
echo "</br>";
//函数返回值
echo "例二:函数返回值:</br>";
function total($price,$number){
$total = $price*$number;
return $total;
}
$sum=0;
$phone = total(5000,2);
$computer = total(8000,10);
$sum=$phone+$computer;
echo "合计".$sum."元";
?>