Home  >  Article  >  Backend Development  >  How to get the parameter value of the current method in php

How to get the parameter value of the current method in php

青灯夜游
青灯夜游Original
2021-10-18 18:47:423103browse

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()".

How to get the parameter value of the current method in php

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:

How to get the parameter value of the current method in php

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:

How to get the parameter value of the current method in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn