Method: 1. Using func_get_arg(), you can return the parameter value at the specified position in the current method, the syntax is "func_get_arg (value)"; 2. Using func_get_args(), you can return a value containing all parameter values of the current method. An array, syntax "func_get_args()".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php Get the current method Parameter value
Method 1: Use the func_get_arg() function
The func_get_arg() function can return the parameter value at the specified position in the current method
Example:
<?php header("Content-type:text/html;charset=utf-8"); class Website { public function Write(){ echo "第二个参数值为: " . func_get_arg(1) . "<br />\n"; } } $object = new Website(); $object -> Write(1,2,3); ?>
Output result:
Method 2: Use the func_get_args() function
func_get_args() can return an array containing all parameter values of the current method
Example:
<?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); ?>
Output result:
Recommended Study: "PHP Video Tutorial"
The above is the detailed content of How to get the parameter value of the current method in php. For more information, please follow other related articles on the PHP Chinese website!