如何删除循环characters_to_eliminate
中每个字符串的第一个字符?foreach
编辑:characters_to_eliminate
是 3 个随机字符,它们并不总是相同的。在第 6 行,我尝试:
$val = substr($val, 3);
但仅删除数组中第一个值的前 3 个字符。
function multiexplode ($delimiters,$string) {
$ary = explode($delimiters[0],$string);
array_shift($delimiters);
if($delimiters != NULL) {
foreach($ary as $key => $val) {
$ary[$key] = multiexplode($delimiters, $val);
}
}
return $ary;
}
// Example of use
$string = "characters_to_eliminate abc, characters_to_eliminate def: characters_to_eliminate ghi, characters_to_eliminate jkl";
$delimiters = Array(",",":");
$res = multiexplode($delimiters,$string);
echo '<pre>';
print_r($res);
echo '</pre>';