This article mainly introduces the PHP division combined with two strings of the function, an example of PHP for string manipulation of the relevant skills, the need for friends can refer to the following
The example in this paper describes the function of PHP splitting and merging two strings. Share to everyone for your reference. The implementation method is as follows:
Here the implementation of the two string to split the merge, such as STR1=AAAA,STR2=BBBB, after the merge generated Abababab
/** * Merges the strings in a-a-to-a pattern like ababab would be * the result. * * @param string $str 1 string A * @param string $str 2 string B * @return String merged String */function Mergebe Tween ($str 1, $str 2) {//Split both strings $str 1 = str_split ($str 1, 1); $str 2 = Str_split ($str 2, 1); Swap variables if string 1 is larger than String 2 if (count ($str 1) >= count ($str 2)) List ($str 1, $str 2) = Array ( $str 2, $str 1); Append the shorter string to the longer string for ($x =0; $x < count ($str 1); $x + +) $str 2[$x]. = $str 1[$x]; Return implode (", $str 2);} Example Demo: Print Mergebetween (' abcdef ', '). "\ n";p rint mergebetween (', ' abcdef '). "\ n";p rint mergebetween (' BB ', ' AA '). "\ n";p rint mergebetween (' aa ', ' BB '). "\ n";p rint mergebetween (' A ', ' B '). "\ n";/*output:a_b_cdefa_b_cdefbabaababab*/