Php function, php function manual _ PHP Tutorial

Source: Internet
Author: User
Tags php form
Php function, php function manual. Php functions: the real power of php functions comes from its functions. PHP provides over 1000 built-in functions. In this chapter, we will explain how to create your own php functions and the php function manual.

The real power of PHP comes from its functions.

PHP provides over 1000 built-in functions.

In this chapter, we will explain how to create your own functions.

To execute the script during page loading, you can put it in the function.

A function is executed by calling a function.

You can call a function anywhere on the page.

Create a PHP function

A function is executed by calling a function.

Syntax
Function functionName () {code to be executed ;}

PHP function principles:

  • The function name should prompt its function
  • Function names start with letters or underscores (cannot begin with numbers)

Instance

A simple function can output my name when it is called:

 

Output:

My name is Kai Jim Refsnes

PHP functions-add parameters

To add more functions to a function, we can add parameters. Parameters are similar to variables.

The parameter is specified in brackets after the function name.

Instance 1

The following instances output different names, but the last names are the same:

 ";}echo "My name is ";writeName("Kai Jim");echo "My sister's name is ";writeName("Hege");echo "My brother's name is ";writeName("Stale");?>

Output:

My name is Kai Jim Refsnes.My sister's name is Hege Refsnes.My brother's name is Stale Refsnes.

Instance 2

The following functions have two parameters:

 ";}echo "My name is ";writeName("Kai Jim",".");echo "My sister's name is ";writeName("Hege","!");echo "My brother's name is ";writeName("Ståle","?");?>

PHP function-return value

If you want the function to return a value, use the return statement.

Instance

 

Output:

1 + 16 = 17

Address: http://www.manongjc.com/php/php_functions.html

Related reading:

Php instance to get the checkbox value of all the check boxes of the form

Php checks whether the check box checkbox is selected

How does php obtain the checkbox value?

Php complete form submission example

Php form submission for detailed analysis

The real power of PHP comes from its functions. PHP provides over 1000 built-in functions. In this chapter, we will explain how to create your own...

Related Article

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.