php·初体验05

php·初体验05

效果:


代码:

<?php
/**
 * Created by PhpStorm.
 * User: liupe
 * Date: 2018-05-25
 * Time: 17:40
 */

//函数
//没有参数
function writeName0()
{
    echo "Kai Jim Refsnes";
}

echo "My name is ";
writeName0();
echo "<br><br>";

//一个参数
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");

echo "<br>";

//俩个参数
function writeName1($fname,$punctuation)
{
    echo $fname . " Refsnes" . $punctuation . "<br>";
}
echo "My name is ";
writeName1("Kai Jim",".");
echo "My sister's name is ";
writeName1("Hege","!");
echo "My brother's name is ";
writeName1("Ståle","?");

?>

函数的返回值:

<?php
/**
 * Created by PhpStorm.
 * User: liupe
 * Date: 2018-05-25
 * Time: 17:47
 */

//计算两个数的和
function add($a,$b){
    $count = $a + $b;
    return $count;
}

//计算小明的数学成绩和语文成绩的和(这个也可以使用在从数据库中读取数据并且做加运算)
function count_score(){
    $m = 96;//数学成绩
    $y = 99;//语文成绩
    $sum = add($m,$y);
    echo "小明的总成绩是".$sum;
}

echo count_score();

?>

效果图:



文章来源: php·初体验05

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:php·初体验05