Home > Article > Backend Development > PHP——Function 2_study notes php rounding function php delay function php sorting function
1. Variable function (variable function)
The value of the variable is the name of a function.
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. Callback function
Callback function, the parameter of the function is the name of another function.
<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. Recursive function
A function calling itself within its function body is called a recursive call (the function calls itself inside the function)
<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)
Determine whether the function exists, the return value is 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); }); });
The above introduces PHP - Function 2_ study notes, including PHP and functions. I hope it will be helpful to friends who are interested in PHP tutorials.