Ec (2); the PHP function getting started tutorial is the foundation that every php student must master. Well, let's take a look at the php function examples and tutorials. the true power of PHP comes from its functions. In PHP-there are more than 700 built-in functions. ------------------------------------------------------------------------------ PHP functions in script ec (2); script
The PHP function getting started tutorial is the foundation that every php student must master. Well, let's take a look at the php function examples and tutorials.
The true power of PHP comes from its functions.
In PHP, there are more than 7 00 built-in functions.
--------------------------------------------------------------------------------
PHP Functions
In this tutorial, we will show you how to set up your own functions.
For more information about the built-in functions of the reference and examples, visit our PHP reference.
Create a PHP function
A function is a code block that we need when it can be executed.
Create a PHP function:
Change all functions to "function ()"
The name function-the function that should be clear is not identified by its name. Can begin with letters or underscores (not a number)
Add a "("-Support for feature code curl after opening
Code insertion
Add a ")"-this function is mainly used to complete the closing music.
For example
A simple function called:
writeMyName();?>
Use PHP Functions
Now we will use the functional PHP script:
echo "Hello world!
";echo "My name is ";writeMyName();echo ".
That's right, ";writeMyName();echo " is my name.";?>
Output is.
Hello world!My name is Kai Jim Refsnes.That's right, Kai Jim Refsnes is my name
PHP functions-add Parameters
Our first function (writeMyName () is a very simple function. It only writes a static string.
To add more function functions, we can add parameters. A parameter is like a variable.
You may have noticed the name of the function after parentheses, such as writeMyName (). The parameter is enclosed in brackets.
Example 1
In the following example, the names written for the first time are different, but the last names are the same:
"; }
echo "My name is ";writeMyName("Kai Jim");echo "My name is ";writeMyName("Hege");echo "My name is ";writeMyName("Stale");?>Output result.
My name is Kai Jim Refsnes.My name is Hege Refsnes.My name is Stale Refsnes.
Next let's take a look at the function return value.
Instance.
echo "1 + 16 = " . add(1,16);?>
Output result.
1 + 16 = 17