array_map — 为数组的每个元素应用回调函数

http://php.net/manual/zh/function.array-map.php

为数组的每个元素应用回调函数;

应用:

为数组元素添加前缀

$demo = [0=>'demo1',1=>'demo2'];

$test = array_map(function($val) { return 'test' .$val;}, $demo);

var_dump($test); //  array(2) { [0]=> string(5) "testdemo1" [1]=> string(5) "testdemo2" }

  

原文地址:https://www.cnblogs.com/jimz/p/9651299.html