2个回答
2016-01-05
展开全部
$a="abcde12";
$b="abcdf6";
echo "<pre>";
var_dump(diffStr($a,$b));
echo "</pre>";
/*
*比较字符串不同的字符
*@参数:$str1:第一个字符串,$str2:第二个字符串
*@<a href="https://www.baidu.com/s?wd=%E8%BF%94%E5%9B%9E%E5%80%BC&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPHDzrHR4mvc3rj-9mWmv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErH61PW6snWfkP1fsPjfznHT4" target="_blank" class="baidu-highlight">返回值</a>:不同字符串的数组,
*/
function diffStr($str1,$str2){
$sArr1 = str_split($str1);
$sArr2 = str_split($str2);
$num1 = count($sArr1);
$num2 = count($sArr2);
$aNew = array();
if($num1 > $num2){
foreach($sArr1 as $k=>$val){
if($num2 > $k && www.hbbz08.com $val != $sArr2[$k]){
$aNew[] = array('s1'=>$val,'s2'=>$sArr2[$k]);
}elseif($num2 <= $k){
$aNew[] = array("s1"=>$val);
}
}
}elseif($num1 < $num2){
foreach($sArr2 as $k=>$val){
if($num1 > $k && $val != $sArr1[$k]){
$aNew[] = array('s1'=>$sArr1[$k],'s2'=>$val);
}elseif($num1 <= $k){
$aNew[] = array("s2"=>$val);
}
}
}elseif($num1 == $num2){
foreach($sArr1 as $k=>$val){
if($val != $sArr2[$k]){
$aNew[] = array('s1'=>$val,'s2'=>$sArr2[$k]);
}
}
}
return $aNew;
}
$b="abcdf6";
echo "<pre>";
var_dump(diffStr($a,$b));
echo "</pre>";
/*
*比较字符串不同的字符
*@参数:$str1:第一个字符串,$str2:第二个字符串
*@<a href="https://www.baidu.com/s?wd=%E8%BF%94%E5%9B%9E%E5%80%BC&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPHDzrHR4mvc3rj-9mWmv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErH61PW6snWfkP1fsPjfznHT4" target="_blank" class="baidu-highlight">返回值</a>:不同字符串的数组,
*/
function diffStr($str1,$str2){
$sArr1 = str_split($str1);
$sArr2 = str_split($str2);
$num1 = count($sArr1);
$num2 = count($sArr2);
$aNew = array();
if($num1 > $num2){
foreach($sArr1 as $k=>$val){
if($num2 > $k && www.hbbz08.com $val != $sArr2[$k]){
$aNew[] = array('s1'=>$val,'s2'=>$sArr2[$k]);
}elseif($num2 <= $k){
$aNew[] = array("s1"=>$val);
}
}
}elseif($num1 < $num2){
foreach($sArr2 as $k=>$val){
if($num1 > $k && $val != $sArr1[$k]){
$aNew[] = array('s1'=>$sArr1[$k],'s2'=>$val);
}elseif($num1 <= $k){
$aNew[] = array("s2"=>$val);
}
}
}elseif($num1 == $num2){
foreach($sArr1 as $k=>$val){
if($val != $sArr2[$k]){
$aNew[] = array('s1'=>$val,'s2'=>$sArr2[$k]);
}
}
}
return $aNew;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询