Home >Backend Development >PHP Tutorial >Basic tutorial for getting started with php - php function

Basic tutorial for getting started with php - php function

WBOY
WBOYOriginal
2016-07-25 09:00:17882browse
This section introduces you to the functions in PHP. Functions are very important in both procedural programming and object-oriented programming (methods). It is recommended that you have a firm grasp of them.

1. Function is a collection of program instructions to complete a certain function. Can be divided into custom functions and system functions (see php functions in php documentation).

2. Define function:

function 函数名(参数列表){
  语句//方法(函数主体)
  return //返回值
}

The parameter list can be multiple parameters There are multiple parameters, and the type is any type supported in PHP. Function names start with an underscore or a letter Function names are not case sensitive

Example 1,

<?php
//无参函数
function show_info()
{
   $title = "欢迎光临程序员之家_bbs.it-home.org";
   echo $title;
}
//有参函数
function show_info($title)
{
   $i_title = $title;
   echo "欢迎光临" . $i_title;
   //输出结果与上面的函数相同。
}

3. Function calling on PHP page When working on a project, the require_once reference is basically used. (require_once'xx.php').

Thank you for paying attention to the PHP introductory tutorials. This series of PHP basic tutorials will help PHP newbies quickly master the PHP programming language. Programmer's Home will continue to launch PHP-related tutorials for everyone, and I wish you all the best in your learning and progress!



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