PHP functions and applications
1. Custom function: custom function
with parameters
<?php
function cooking($name)
{
echo "买{
$name}所需的菜<br/>";
echo "洗{
$name}菜<br/>";
echo "炒{
$name}菜<br/>";
echo "{
$name}上桌<br/>";
}
cooking("回锅肉");
?>
Running result:
custom function with parameters and return value
<?php
function add($a,$b)
{
return $a + $b;
}
$c = add(5,10);
echo $c;
?>
Running result:
PHP recursive function
<?php
function test(){
static $dig=0;
if($dig++<10){
echo $dig; test();
}
}
test();
?>
Running result:
factorial code:
<?php
//实现阶乘
function leiCheng($n)
{
If($n <=1){
return $n;
} else {
return $n * leiCheng($n-1);
}
}
echo leiCheng(10);
?>
Operating results:
Finally: 180 commonly used functions of PHP are attached: https://www.jb51.net/article/101179.htm