主页
PHP
PHP 回调函数
tryphp_callback_functions
运行 ❯
×
更改方向
保存代码
更改主题
<!DOCTYPE html> <html> <body> <?php // Define the named callback function function myfunction($n) { return($n * $n); } // Array of numbers to multiply $numbers = [1, 2, 3, 4, 5]; // Use array_map with the myfunction function as a callback print_r(array_map("myfunction", $numbers)); ?> </body> </html>
Array ( [0] => 1 [1] => 4 [2] => 9 [3] => 16 [4] => 25 )