How to use the Plants vs. Zombies modifier, how to use the PHP function and how to define the function

WBOY
Release: 2016-07-29 08:42:32
Original
2081 people have browsed it

The syntax for a function is:
Function definition method

Copy code The code is as follows:


function "function_name" (arg1, arg2...)
{
[code to execute]
return [final_result] ;
}


where [final_result] usually returns the variable value from the function.
Let’s see an example

Copy the code The code is as follows:


function double_this_number($input_number)
{
return $input_number*2;
}


Call method

Copy code The code is as follows:


$x = 10;
$y = double_this_number($x);
print $y;


The output value is
10
Okay, let’s look at a more complicated function usage

Copy the code The code is as follows:


function safePost($v=0)
{
if( $v==0 )
{
$protected = array("_GET", "_POST", "_SERVER", "_COOKIE", "_FILES", "_ENV", "GLOBALS");
foreach($protected as $var) {
if(isset($_REQUEST[$var]) || isset($_FILES[$var]) )
{
die("Access denied");
}
}
}
}


Call method
safePost();
This does not need to define parameters, because $v==0 has a parameter set by default, This is very helpful for function expansion.

The above introduces how to use Plants vs. Zombies modifier, how to use PHP functions and how to define functions, including how to use Plants vs. Zombies modifier. I hope it will be helpful to friends who are interested in PHP tutorials.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!