Home >Backend Development >PHP Problem >Can php write methods?

Can php write methods?

藏色散人
藏色散人Original
2021-12-08 09:25:331898browse

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.

Can php write methods?

#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!

Statement:
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