Easy way to apply a function to an array

前端 未结 7 813
無奈伤痛
無奈伤痛 2020-12-03 14:31

I am aware of array_walk() and array_map(). However when using the former like so (on an old project) it failed

array_walk($_POST,          


        
7条回答
  •  情书的邮戳
    2020-12-03 14:57

    I know the OP asked to call a function, however in the cases where you do not really need to call a function you can define an anonymous one:

    $ids = [1,2,3];
    array_walk($ids,function(&$id){$id += 1000;});
    

提交回复
热议问题