如何用PHP中的一个字符替换所有数组值?

时间:2022-02-21 11:46:04

If I have this array: $array = ['1', '2', '3'];

如果我有这个数组:$ array = ['1','2','3'];

I would like to replace all values in that array with asterisk sign *. Essentially, I want to get array like this: $new = ['*', '*', '*'];.

我想用星号*替换该数组中的所有值。基本上,我想得到这样的数组:$ new = ['*','*','*'] ;.

What is the best way to do this ? I am hoping that there is some short simple solution for this.

做这个的最好方式是什么 ?我希望有一些简单的简单解决方案。

Thanks in advance.

提前致谢。

1 个解决方案

#1


1  

<?php
$array = ['1', '2', '3'];
$newarray = array_map(function($val) { return "*"; }, $array);
?>

#1


1  

<?php
$array = ['1', '2', '3'];
$newarray = array_map(function($val) { return "*"; }, $array);
?>