first of dave chen helping me merger.
now ran problem. when merge using code:
$string1 = " ;1 2 3 ;4 "; $string2 = " ;1 ;2 ;3 ;4 ;5 ;6 "; echo implode("\r\n",array_unique(array_merge(explode("\r\n",$string1),explode("\r\n",$string2)))); the output ;1 2 3 ;4 ;2 ;3 ;5 ;6 need ;1 2 3 ;4 ;5 ;6
you can try :
echo implode(" ", crazymerge($string1, $string2)); output
;1 2 3 ;4 ;5 ;6 function used
function crazymerge($a, $b) { // cleanup $a = array_map("trim", explode("\r\n", $a)); $b = array_map("trim", explode("\r\n", $b)); $ab = array(); foreach($a $v) { if (! in_array(ltrim($v, ";"), $ab) && ! in_array($v, $ab)) $ab[] = $v; } foreach($b $k => $v) { if (! in_array(ltrim($v, ";"), $ab) && ! in_array($v, $ab)) $ab[] = $v; } return $ab; }
Comments
Post a Comment