Php notes -- functions (1), php notes -- Functions

Source: Internet
Author: User

Php notes -- functions (1), php notes -- Functions

1. Start with function;

2. The function name can start with a letter or underscore;

3. The function body must be in braces;

 

 1 <?php 2  3 function a_b() { 4  5     echo "hello!!"; 6  7 } 8  9 a_b();10 11 ?>

 

4. php functions can have no parameters or multiple parameters. Separate multiple parameters with commas;

5. the parameter is similar to a variable and must start with $;

 
1 <?php2 3 function a_b($a,$b) {4     echo $a+$b;5 }6 7 a_b(1,2);8 9 ?>

 

6. The return keyword allows the function to return values;

 

<?phpfunction a_b($a,$b) {    return $a+$b;}$h_b = a_b(1,2);echo $h_b;?>

 

7. The function cannot return multiple values;

 

8. built-in functions are supported by php by default;


9. Use function_exists in php to determine whether a function exists;
 

 1 <?php 2  3 function a_b() { 4     echo "hello"; 5 } 6  7 if (function_exists('a_b')) { 8      9     echo 'yes';10 }11 12 ?>

 

10. The function is not executed immediately when the page is loaded;


11. The function is executed only when it is called;

 

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.