<?php
/**
* 声明语法
* 调用方式
* 参数设置
* 返回值
* 作用域
*/
//声明
function hello() //无论有无参数,括号 不能省
{
echo '欢迎来到全城货的汽贸(广东)有限公司';
}
//调用:按名调用,必须还上括号,不能没有参数
hello();
echo '<hr>';
//设置参数
function hello1($siteName) //无论有无参数,括号 不能少
{
echo '欢迎来到'.$siteName.'看车';
}
hello1('全城货的官方网站');
echo '<hr>';
//默认参数:
function hello2($siteName='全城货的官方网站')
{
echo '欢迎来到'.$siteName.'预约看车试乘!';
}
//hello2();
hello2('www.huodi100.net');
//
//当有多种类型的参数共存的时候:普通参数与默认参数共存
echo '<hr>';
function hello3($name,$siteName='全城货的官方网站',$lang='huodi100.net') //注意:复制过来的hello2要记得改成hello3
{
echo '我是'.$name.',欢迎来到'.$siteName.'预约看车试乘!'.$lang;
}
hello3('黄经理');
echo '<hr>';
function hello4($name,$lang='huodi100.net',$siteName='全城货的官方网站') //注意:复制过来的hello2要记得改成hello3
{
echo '我是'.$name.',欢迎来到'.$siteName.'预约看车试乘!'.$lang;
}
hello4('黄经理','huodi100.net','广州全城货的运输有限公司');点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号