Basic structure of PHP functions

Source: Internet
Author: User
PHP Functionsis particularly common, convenient for multiple reuse and maintenance, so be sure to understand PHP FunctionsThe basic structure of what kind of, mastered the PHP FunctionsBasic structure It's a lot easier to understand what's deep.

Structure of PHP functions

Building a function

function get_sum ($a, $b) {  $c = $a + $b;   return $c; } $sum = Get_sum (3,5)//call echo $sum; Output

The basic structure of the build function

    • Keyword: function

    • Function Name: get_sum

    • Parameters: ($a, $b)

    • Function Body: {$c = $a + $b}

    • Return value: Return $c

function naming rules:

Valid functions must begin with a letter or underscore, followed by letters, numbers, and underscores.

The return value of the function:

Defined

    • Value is returned by a return statement

    • can return any type

    • The return statement immediately terminates the function and gives control to the line of code that called the function

function is an essential knowledge point in PHP and must be mastered

Related recommendations:

php function Trim () instance

Examples of how PHP functions use a variable number of parameters

What is the use of PHP functions before & symbols?

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.