国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Basic functions of PHP development tutorial

1. Overview of PHP functions

The real power of PHP comes from its functions.

In PHP, more than 1000 built-in functions are provided.

Function is function. Calling a function is calling a function.

2. PHP built-in functions

The date() and rand() functions we used earlier are all built-in functions of the system. Details When you use it in the future, please check the PHP manual. There are detailed examples above. In the advanced tutorials that follow, there will also be an introduction to commonly used functions. In this chapter, our focus is on how to create our own functions.


3. PHP custom function

1. Create a function

Syntax:

function functionName()
{
Code to be executed;
}

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)

Note : There is no semicolon after the curly braces

2. Call the function

Syntax:

functionName;

Write Function names can be separated by semicolons

A simple example: the code is as follows

<?php
//定義一個(gè)輸出名字的函數(shù)
function myName(){
    echo "小明";    
}
echo "大家好,我叫";
//調(diào)用函數(shù)
myName();
?>


##4. Add parameters to the custom function

When calling a custom function, pass in point information to the function.

Example: The code is as follows

<?php
//定義一個(gè)個(gè)人信息的函數(shù)
function information($name,$age){
    echo "大家好,我叫".$name.",今年已經(jīng)".$age."歲了。";
}
//調(diào)用函數(shù),帶兩個(gè)參數(shù)
information("小明",18);
?>

This method of adding parameters will be very common in our future study and work


5. The return value of the function

If you need to let the function return A value, use the return statement.

Example, the code is as follows

<?php
//定義函數(shù),傳入?yún)?shù),計(jì)算兩個(gè)參數(shù)之和,并且返回出該值
function add($x,$y)
{
    $total=$x+$y;
    return $total;
}
//調(diào)用該函數(shù)
echo "1 + 18 = " . add(1,18);
?>
Continuing Learning
||
<?php //定義一個(gè)輸出名字的函數(shù) function myName(){ echo "小明"; } echo "大家好,我叫"; //調(diào)用函數(shù) myName(); ?>
submitReset Code