Home > Article > Backend Development > Can php write methods?
php can write methods, the steps to create a method: 1. Create a PHP sample file; 2. Define a function method through "function functionName(){...}"; 3. Write it in the method body Just the code to be executed.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
Can I write methods in php?
php can write methods, and methods refer to functions, so it is very simple to create PHP functions:
Functions are executed by calling functions.
Syntax
<?php function functionName() { // 要执行的代码 } ?>
PHP function guidelines:
The name of the function should hint at its function
The function name starts with a letter or underscore (not a number Beginning)
Example
A simple function that outputs my name when called:
Example
<?php function writeName() { echo "Kai Jim Refsnes"; } echo "My name is "; writeName(); ?>
Output:
My name is Kai Jim Refsnes
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can php write methods?. For more information, please follow other related articles on the PHP Chinese website!