PHP split a function instance combining two strings, PHP string function instance
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-strings in a-a-to-a pattern like ababab would be is * the result. * * @param string $str 1 string A * @param string $str 2 string B * @return string Merged String */function Mergebetween ($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];< C17/>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*/
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1019452.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019452.html techarticle PHP Split Merge two strings of function instances, PHP String Function Example This article describes the PHP split merge two strings of the function. Share to everyone for your reference. Concrete implementation of the party ...