3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = "9121221212119"; $calculate = function($input) { $sum = 0; $previousChar = $input[strlen($input) - 1]; foreach(str_split($input) as $char) { if ($char === $previousChar) { $sum += (int)$char; } $previousChar = $char; } return $sum; }; var_dump($calculate($input));
based on VDHhK
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
int(12)