函数必须调用才能执行,可以在声明之前调用,也可以在声明之后调用
代码如下:
/* 函数定义:
* 1.函数是一个被命名的
* 2.独立的代码段
* 3.函数执行特定任务
* 4.并可以给调用它的程序返回一个值
*
* 函数的优点:
* 1.提高程序的重用性
* 2.提高程序的可维护性
* 3.可以提高开发效率
* 4.提高软件的可靠性
* 5.控制程序的复杂性
*
* 函数的声明
* function 函数名(){
*
* }
*
* function 函数名(参数1,参数2,参数...)
* {
* 函数体
* }
*
* function 函数名()
* {
* 函数体;
* 返回值;
* }
* function 函数名(参数列表...)
* {
* 函数体;
* 返回值
* }
*
* 注意:
* 一、函数必须调用才能执行,可以在声明之前调用,也可以在声明之后调用
* 二、函数名命名和变量一样,aaa bbb ccc aaaBbbCcc(第一单词小写,以后每个单词首字母大写)
* 三、函数在声明时不能重名
* 四、可以通过向函数传递参数,改变函数的行为
* 形参:在声明函数时,声明的参数,参数就是变量,多个参数用,分开
* 实参:调用函数时传给形参数值(数据,也可以是变量)
* 五、如果没有返回值则称为过程
* 六、通过使用return语句返回数据
* 七、函数执行到return语句就结束,不要再这个语句后写代码,也可以用return结束函数的执行
*
* 函数名的作用:
* 1.调用函数,开始执行函数
* 2.可以向函数中传递数据
* 3.函数名就是返回的值
*
*
*/
//一个输出表格的函数
function table($tablename,$width,$row,$col)
{
echo '
'.($i*$row+$j).' echo '
}/td>'; } echo ' |
}
table("输出表格",600,10,10);
table("输出表格2",300,6,6);
//另一种输出方式
function table2($tablename,$width,$row,$col)
{
$str='
'.($i*$row+$j).' | ';
return $str;
}
echo table2("直接输出表格",400,15,15);
?>
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks agoByDDD

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools