function fnArea() {return 20.5;}echo fnArea();
function fnArea($pi,$r){return $pi * $r * $r;}echo fnArea(3.14,10);
function fnArea(&$pi) {$pi ++;}$mypi = 3.14;fnArea($mypi); //传递的实参必须是变量echo $mypi; //4.14,pi就像mypi的影子,$pi的数据是和$mypi对应的
function fnList() {$count = 0;for ($i = 0; $i < func_num_args(); $i++) {$count += func_get_arg($i);}return $count;}echo fnList(1,2,3); //6,这里通过将传入的参数累加
function fnArea ($r, $pi=3.14) { //位置不能动,仅只能在右边设值return $pi * $r * $r;}echo fnArea(10);
function fnList($name) {$count = 1;echo $name . '第' . $count . '次访问</br>';}fnList('sea');echo $count; // Notice: Undefined variable: count 报错echo $name; // Notice: Undefined variable: name 报错
$count = 10;function fnList($name) {global $count;echo $name . '第' . $count . '次访问</br>';$count++;}fnList('sea');echo $count; //11
function fnList($name) {static $count = 1;echo $name . '第' . $count . '次访问</br>';$count++;}fnList('sea'); //sea第1次访问fnList('sea'); //sea第2次访问fnList('sea'); //sea第3次访问
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号