PHP函数初识(1)

PHP函数初识(1)

                                                        函数

php函数的定义方式:

修饰符  function 函数名(参数1,参数2...){

    执行体.

}

修饰符: 

public :公有的.(默认权限)

private : 私有的.  

protected:受保护的. 
1:必须要使用关键字'function' ;
2:函数名可以是字母或下划线开头.
3:在大括号中编写函数体.
判断函数是否存在:
    function_exists('函数名');
  注意点:函数调用不区分大小写。
  例如:
  Name()=========》name();
  变量可以按引用传递,在参数前加&;
  $ceshi=10;
  function test4(&$a){
		$a=80;
}
	test4($ceshi);
	echo $ceshi;//值被改变
 <?php
	$ceshi = 10;
	//无参无返回值
	function test(){
		echo "Hello PHP";
	}
	test();
	echo "<br/>";
	echo "<br/>";
	//无参有返回值
	function test1(){
		$ceshi2 = 50;
		return $ceshi2; 
	}
	$c  =test1();
	echo $c ;
	echo "<br/>";
	echo "<br/>";
	//有参无返回值
	function test2($ceshi){
		$ceshi = 30;
	}
	test2($ceshi);
	echo $ceshi;//值不会被改变
	echo "<br/>";
	echo "<br/>";
	//有参有返回值
	function test3($ceshi){
		$num = $ceshi*15;
		return $num;
	}
	 $num = test3($ceshi);

	echo $num;
	//可变函数:
	//通过变量的值来自己调用函数.
	$func = 'test';
	$func();
	$func = 'test1';
	$func();
	$func = 'test2';
	$func($ceshi);
	$func = 'test3';
	$func($ceshi);