Rumah >pembangunan bahagian belakang >tutorial php >PHP——函数二_学习笔记 php四舍五入函数 php延时函数 php排序函
1.变量函数(可变函数)
变量的值是一个函数的名称。
e.g:
<code>``` <span><span>function</span><span>show</span><span>(<span>$a</span>,<span>$b</span>)</span>{</span><span>return</span><span>$a</span>+<span>$b</span>; } <span>$str</span>=<span>"show"</span>; <span>echo</span><span>$str</span>(<span>10</span>,<span>5</span>); ``</code>
2.回调函数
回调函数,函数的参数是另一个函数的名字。
<code>``` <span><span>function</span><span>show</span><span>(<span>$a</span>,<span>$b</span>)</span>{</span><span>return</span><span>$a</span>+<span>$b</span>; } <span><span>function</span><span>test</span><span>(<span>$i</span>,<span>$j</span>,<span>$k</span>)</span>{</span><span>return</span><span>$k</span>(<span>$i</span>,<span>$j</span>); } <span>$num</span>=test(<span>10</span>,<span>5</span>,<span>"show"</span>); <span>echo</span><span>$num</span>; ``</code>
3.递归函数
一个函数在它的函数体内调用它自身称为递归调用(函数内部自己调用自己)
<code><span><span>function</span><span>test</span><span>()</span>{</span><span>static</span><span>$num</span>; <span>$num</span>++; <span>if</span>(<span>$num</span>10){ <span>echo</span><span>'this is num '</span>.<span>$num</span>.<span>'<br>'</span>; test();<span>//自己再调用自己</span> } } test();</code>
4.function_exits(string $function_name)
判断一下函数是否存在,返回的是bool;
<code><span>if</span>(function_exists(<span>'show'</span>)){ <span>exit</span>(<span>'此函数名称已存在'</span>); }<span>else</span>{ <span><span>function</span><span>show</span><span>()</span>{</span> } } var_dump(function_exists(<span>'show'</span>));</code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介绍了PHP——函数二_学习笔记,包括了php,函数方面的内容,希望对PHP教程有兴趣的朋友有所帮助。