方法:1、利用func_get_arg(),可返回當(dāng)前方法中指定位置的參數(shù)值,語法“func_get_arg(數(shù)值)”;2、利用func_get_args(),可返回包含當(dāng)前方法所有參數(shù)值的一個數(shù)組,語法“func_get_args()”。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦
php獲取當(dāng)前方法的參數(shù)值
方法1:利用func_get_arg()函數(shù)
func_get_arg()函數(shù)可返回當(dāng)前方法中指定位置的參數(shù)值
示例:
<?php header("Content-type:text/html;charset=utf-8"); class Website { public function Write(){ echo "第二個參數(shù)值為: " . func_get_arg(1) . "<br />n"; } } $object = new Website(); $object -> Write(1,2,3); ?>
輸出結(jié)果:
方法2:利用func_get_args()函數(shù)
func_get_args()可返回包含當(dāng)前方法所有參數(shù)值的一個數(shù)組
示例:
<?php header("Content-type:text/html;charset=utf-8"); class Website { public function Write(){ $arg_list = func_get_args(); var_dump($arg_list); } } $object = new Website(); $object -> Write(1,2,3); ?>
輸出結(jié)果:
推薦學(xué)習(xí):《PHP視頻教程》