关于树形回复的字符串操作问题

上回要的是
1.0,2.1,3.2,4.2,6.1,88.2,10.2,90.3,9.1
呵呵

function add($f,$n,$s){
$arr=explode(",",$s);
if($p=array_search ($f,$arr)){
$tmp=explode(".",$arr[$p]);
$d=$tmp[1]+1;
$notFound=true;
for($i=$p+1;$i<count($arr);$i++){
$tmp=explode(".",$arr[$i]);
if($tmp[1]<$d){
$notFound=false;
$arr[$i]="$n.$d,".$arr[$i];
break;
}
}
if($notFound)$arr[]="$n.$d";
}
return implode(",",$arr);
}
$str="1.0,2.1,3.2,4.2,6.1,88.2,90.3,9.1";
$str=add("6.1","101",$str);
echo $str." ";
$str=add("90.3","140",$str);
echo $str." ";
$str=add("88.2","141",$str);
echo $str." ";

Published At
Categories with Web编程
Tagged with
comments powered by Disqus