如何删除一行数组中所有值的所有哈希字符


How to Remove all hash character of all values of an array with one line

我有一个数组,我想从它的所有值中删除所有# char:

$array = ('#test' , '#test1' , '#test2' ... etc);

我知道如何用"Foreach"或"for"或任何函数删除所有特殊字符但我需要找出是否有办法从PHP中一个或最多两行数组的所有值中删除特殊字符

亲切的问候

Simple do an array_walk

<?php
$array = ['#test' , '#test1' , '#test2','nohash','#test4'];
array_walk($array,function (&$v){ if(strpos($v,'#')!==false){ $v = str_replace('#','',$v);}},$array);
print_r($array);

OUTPUT :

Array
(
    [0] => test
    [1] => test1
    [2] => test2
    [3] => nohash
    [4] => test4
)

如果你不需要测试第一个字符,那就简单多了:

$array = str_replace('#', '', $array);