<<< Previous question <<< Question ID#0678.md >>> Next question >>>
What is the output of the following code?
$newstring = '';
$string = "111221";
for($i = 0; $i < strlen($string); $i++) {
$current = $string[$i];
$count = 1;
while(isset($string[$i + $count]) && ($string[$i + $count] == $current))
$count++;
$newstring .= "$count{$current}";
$i += $count-1;
}
print $newstring;
- A) 312211
- B) 3312212
- C) 11221221
- D) 221131
Answer
Answer: A