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

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

青灯夜游
Release: 2023-03-13 11:30:01
Original
3148 people have browsed it

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);
?>
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template