PHP function getting started tutorial-PHP source code

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.