what is php function

(*-*)浩
Release: 2023-02-23 21:16:02
Original
3040 people have browsed it

A function refers to a program that is put together to do a certain thing. Also called subroutine, (in OOP) method.

what is php function

The real power of PHP comes from its functions: it has over 1000 built-in functions.

PHP User-Defined Functions

In addition to the built-in PHP functions, we can create our own functions.

A function is a block of statements that can be used repeatedly in a program.

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

Function will only be executed when called. (Recommended learning: PHP programming from entry to proficiency)

Creating user-defined functions in PHP

User-defined functions are declared with the word "function "Starts:

Syntax

function functionName() {
  被执行的代码;
}
Copy after login

Note: Function names can start with letters or underscores (not numbers).

Note: Function names are not case-sensitive.

Tip: The function name should reflect the task performed by the function.

In the following example, we create a function named "writeMsg()". An opening brace ({) indicates the beginning of a function's code, while a closing brace (}) indicates the end of the function. This function outputs "Hello world!". To call this function, just use the function name:

Example

<?php
function sayHi() {
  echo "Hello world!";
}

sayhi(); // 调用函数?>
Copy after login

The above is the detailed content of what is php function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!