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" }

  

posted @ 2018-09-15 16:31  百事可口  阅读(148)  评论(0)    收藏  举报