问题描述不清楚
$phone
是什么类型?数组?如果是一维数组,使用...
不就展开了吗?不能再使用array_walkmb_substr_replace
这个函数不是自带函数啊,应该附上代码
$phone = [];
foreach (range(1, 5000) as $number) {
$phone[] = '1591234'.str_repeat('0',4-strlen($number)).$number;
}
replacePhone($phone);
foreach ($phone as $number) {
echo $number;
echo PHP_EOL;
}
function replacePhone(&$phone){
array_walk($phone, function (&$item) {
$item = mb_substr_replace($item, '****', 3, 4);
});
}
function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = "UTF-8") {
if (extension_loaded('mbstring') === true){
$string_length = (is_null($encoding) === true) ? mb_strlen($string) : mb_strlen($string, $encoding);
if ($start < 0) { $start = max(0, $string_length + $start); }
else if ($start > $string_length) {$start = $string_length; }
if ($length < 0){ $length = max(0, $string_length - $start + $length); }
else if ((is_null($length) === true) || ($length > $string_length)) { $length = $string_length; }
if (($start + $length) > $string_length){$length = $string_length - $start;}
if (is_null($encoding) === true) { return mb_substr($string, 0, $start) . $replacement . mb_substr($string, $start + $length, $string_length - $start - $length); }
return mb_substr($string, 0, $start, $encoding) . $replacement . mb_substr($string, $start + $length, $string_length - $start - $length, $encoding);
}
return (is_null($length) === true) ? substr_replace($string, $replacement, $start) : substr_replace($string, $replacement, $start, $length);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…