How to declare and apply various forms of php functions

Source: Internet
Author: User
You can define functions when writing php programs. of course, it is best to define functions that are directly available in the php System. Many standard functions are available in the php System, but some functions need to be compiled together by the specific php extension module, otherwise, a fatal "undefined function" error will be generated when you use them. You can define functions when writing php programs. of course, it is best to define functions that are directly available in the php System. Many standard functions are available in the php System, but some functions need to be compiled together with specific php extension modules. Otherwise, a fatal" Undefined function. For example, to use the image function imagecreatetruecolor (), add GD support when compiling php; or use the mysql_connect () function, you need to add MYSQL support when compiling php. Many core functions are included in php of each version, such as strings and variable functions. Call the phpinfo () or get_loaded_extensions () function to find out which extension libraries PHP has loaded. Note that many extension libraries are valid by default.

The method for calling system functions is the same as that for calling custom functions. Every function provided by the system has detailed help information. Therefore, when using a function, it is not necessary to spend a lot of time studying how the function is executed internally, you only need to refer to the help document to complete the function call and implement the functions we need. Of course, if you declare a function for others to apply it, you should also provide a detailed description of the function. If you want to successfully apply a function through the help documentation, you need to introduce the help documentation for using the function.Including the following points:

1. function description (determines whether to use this function ).

To use a function to complete any task, you need to base the task. Therefore, you can use the function description to determine whether to use the function in your own script.

2. parameter description (decide how to use this function)

The role of a parameter is to import some numeric values before the function is executed. You can change the internal execution behavior of a function by passing values of function parameters, therefore, detailed descriptions of how to transmit values, what values are passed, what types of values are passed, and how many values are passed are the key to determining how to use functions.

3. return value (how to handle it after the call)

In the script, you can obtain the return value after the function is called to determine the next execution of the program. Therefore, you must know whether the function has a returned value, what value is returned, and what type of value is returned.

The following is an example of a user-defined function, which contains the help information of the above three aspects:

 

PHPFunction parametersIt is the standard that determines how to successfully apply a function or control the execution behavior of a function. Because PHP is a weak type language, there are many ways to set and apply parameters. Therefore, you can declare functions with different parameters and call functions with various parameters, is the key to learning functions. The following describes the parameters and applications of the PHP function.

[Recommended tutorials]

1. php1.cn Dugu jiujian (4)-php video tutorial

2. php programming from getting started to mastering a full set of video tutorials

3. php video tutorial

The above describes how to declare and apply various forms of php functions. For more information, see other related articles in the first PHP community!

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.