[PHP函数]①0--函数实战

");
    }
    switch ($op) {
        case '+':
            $res = $num1 + $num2;
            break;
        case '-':
            $res = $num1 - $num2;
            break;
        case '*':
            $res = $num1 * $num2;
            break;
        case '/':
            if ($num2 != 0) {
                $res = $num1 / $num2;
            } else {
                exit('0不能当做除数');
            }
            break;
        case '%':
            $res = $num1 % $num2;
            break;
    }
    return "{$num1}{$op}{$num2}={$res}";
}

function getDateStr($del1 = '年', $del2 = '月', $del13 = "日")
{
    $dayArr = array("一", "二", "三", "四", "五", "六", "日");
    $day = date("w");
    return date("Y{$del1}m{$del2}d{$del13} 星期") . $dayArr[$day];
}

?>
";
echo calc(2, 3, '*');
echo "
"; echo calc("1", 2, "-"); echo "
"; echo calc(3, 2, "/"); echo "
"; echo getDateStr(); echo "
"; echo getDateStr("/", "/", null); echo "
"; echo getDateStr("^_^", "^_^", "^_^"); ?>
[PHP函数]①0--函数实战_第1张图片
Paste_Image.png

你可能感兴趣的:([PHP函数]①0--函数实战)