Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 644 Bytes

0678.md

File metadata and controls

35 lines (25 loc) · 644 Bytes

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