|
.創(chuàng)建可以調(diào)用的函數(shù)以便重用代碼
.把參數(shù)傳遞給函數(shù)并且從函數(shù)返回值和腳本的不同部分中的變量和數(shù)據(jù)進(jìn)行交互
.把代碼和函數(shù)組存入到其他文件中,并且我們的腳本內(nèi)包含這些文件.
3.1基本代碼重用:函數(shù)
3.1.1 定義和調(diào)用函數(shù)
關(guān)鍵字function通知php這是一個(gè)函數(shù),后面跟著的是函數(shù)的名稱,它可以是字母、數(shù)字、字符或下劃線
函數(shù)名稱之后是參數(shù)列表,然后是函數(shù)體。在其它語(yǔ)言中名稱相同、但是參數(shù)列表不同的函數(shù),php不支持這一特性。
復(fù)制代碼 代碼如下:
<?php
function booo_spooky()
{
echo "I am booo_spooky. This name is okay!<br/>/n";
}
function ____333434343434334343()
{
echo <<<DONE
I am ____333434343434334343. This is an awfully
unreadable function name. But it is valid.
DONE;
}
//
// This next function name generates:
//
// Parse error: syntax error, unexpected T_LNUMBER,
// expecting T_STRING in
// /home/httpd/www/phpwebapps/src/chapter03/playing.php
// on line 55
//
// Function names cannot start with numbers
//
function 234letters()
{
echo "I am not valid<br/>/n";
}
//
// Extended characters are ok.
//
function grüß_dich()
{
echo "Extended Characters are ok, but be careful!<br/>/n";
}
//
// REALLY extended characters are ok too!! Your file will
// probably have to be saved in a Unicode format though,
// such as UTF-8 (See Chapter 5).
//
function 日本 主站蜘蛛池模板: 开阳县| 阳西县| 新巴尔虎左旗| 喀什市| 城步| 黑河市| 革吉县| 哈尔滨市| 韶山市| 乡城县| 从化市| 清远市| 石阡县| 金山区| 珠海市| 蕲春县| 舞阳县| 故城县| 七台河市| 营口市| 阜城县| 泉州市| 清新县| 元阳县| 南投县| 济阳县| 黄冈市| 道孚县| 垦利县| 寻乌县| 裕民县| 盘锦市| 金秀| 玉门市| 香港 | 南投县| 鱼台县| 凤台县| 嫩江县| 芒康县| 浦江县|