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><=<span>10</span>){ <span>echo</span><span>'this is num '</span>.<span>$num</span>.<span>'<br>'; 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教學有興趣的朋友有幫助。