PHP-数组函数array_map()

"google","b"=>"baidu","y"=>"yahoo");
  //输出原数组
  echo "
";
  print_r($websites);
  echo "
"; //定义对单个数组处理的回调函数 function change_value($value){ return ucfirst($value).".com"; } $urls=array_map('change_value',$websites); echo "
";
  print_r($urls);
  echo "
"; //多个数组使用的例子 $arr1=array(1,3,5,7); $arr2=array(2,4,6,8); //定义对多个数组处理的回调函数 function func1($a,$b){ return $a*$b; } $results=array_map('func1',$arr1,$arr2); echo "利用回调函数对多个数组处理后,返回的结果:
"; echo "
";
  print_r($results);
  echo "
";

运行结果如下:

Array
(
    [g] => google
    [b] => baidu
    [y] => yahoo
)
Array
(
    [g] => Google.com
    [b] => Baidu.com
    [y] => Yahoo.com
)
利用回调函数对多个数组处理后,返回的结果:
Array
(
    [0] => 2
    [1] => 12
    [2] => 30
    [3] => 56
)

你可能感兴趣的:(PHP-数组函数array_map())