/**
* Merges two strings in a way that a pattern like ABABAB will be
* the result.
*
* @param string $str1 String A
* @param string $str2 String B
* @return string Merged string
*/
function MergeBetween($str1, $str2){
// Split both strings
$str1 = str_split($str1, 1);
$str2 = str_split($str2, 1);
// Swap variables if string 1 is larger than string 2
if (count($str1) >= count($str2))
list($str1, $str2) = array($str2, $str1);
// Append the shorter string to the longer string
for($x=0; $x < count($str1); $x++)
$str2[$x] .= $str1[$x];
return implode('', $str2);
}
//范例演示:
print MergeBetween('abcdef', '__') . "\n";
print MergeBetween('__', 'abcdef') . "\n";
print MergeBetween('bb', 'aa') . "\n";
print MergeBetween('aa', 'bb') . "\n";
print MergeBetween('a', 'b') . "\n";
/*
Output:
a_b_cdef
a_b_cdef
baba
abab
ab
*/
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有