Home > Backend Development > PHP Tutorial > What are the things to note about functions in php?

What are the things to note about functions in php?

零下一度
Release: 2023-03-10 16:20:02
Original
1630 people have browsed it

1. Start with function##;

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

3. The function body must be within curly brackets;

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

4.php function There can be no parameters or multiple parameters. If there are multiple parameters, they must be separated by commas ;

##5. The parameter is similar to a variable and should start with $;

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

## 6.return Key Words can make the function return a value;

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

7. Functions cannot return multiple values;

8. Built-in functions are functions supported by PHP itself by default;

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

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

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

##11. The function will only be executed when it is called;

The above is the detailed content of What are the things to note about functions in php?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template