有人可以帮我做这个爆炸函数递归吗?我的头今天不工作。
function expl($str,$charlist='|'){
$charlist = str_split($charlist);
foreach($charlist as $char){
if(is_array($str)){
for($i=0; $i<sizeof($str); $i++){
$str[$i] = expl($str[$i],$char);
}
}else{
return (explode($char,trim($str,$char)));
}
}
return($str);
}
echo "<pre>";
print_r(expl("A~a1~a2|B~b1~b2",'|~'));
echo "</pre>";
应该输出:
Array
(
[0] => Array
(
[0] => A
[1] => a1
[2] => a2
)
[0] => Array
(
[0] => B
[1] => b1
[2] => b2
)
)