1.给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”。比如字符串AAAABCCDAA会被编码成4A1B2C1D2A。(有问题)
<?php
function string($string=''){
$arr = array_count_values(str_split($string));
$string_num = '';
foreach ($arr as $k => $v) {
$string_num .= $k . $v;
}
return $string_num;
}
echo string('AAAABCCDAA');