LoginSignup
0
0

More than 5 years have passed since last update.

array_map(コールバック関数)の小さなサンプル

Posted at

コード

test.php
<?php
function sum($param){
        return $param + 1;
}

$arr = array(1,2);
$result = array_map("sum", $arr);

var_dump($result);

$result = array_map(function ($param){
        return $param + 10;
}, $arr);
var_dump($result);

実行

$ php test.php
array(2) {
  [0]=>
  int(2)
  [1]=>
  int(3)
}
array(2) {
  [0]=>
  int(11)
  [1]=>
  int(12)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0