Skip to content

PHP函数 #8

@suhao

Description

@suhao

PHP 的真正威力源自于它的函数。

在 PHP 中,提供了超过 1000 个内建的函数。

任何有效的 PHP 代码都有可能出现在函数内部,甚至包括其它函数和类定义。

创建 PHP 函数

function functionName() {
  // 要执行的代码;
}

添加参数

<html>
 <body>

 <?php
 function writeName($fname)
 {
 echo $fname . " Refsnes.<br>";
 }

 echo "My name is ";
 writeName("Kai Jim");
 echo "My sister's name is ";
 writeName("Hege");
 echo "My brother's name is ";
 writeName("Stale");
 ?>

 </body>
 </html>

返回值

<html>
 <body>

 <?php
 function add($x,$y)
 {
 $total=$x+$y;
 return $total;
 }

 echo "1 + 16 = " . add(1,16);
 ?>

 </body>
 </html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions