3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ["W", "L", "W", "W"]; $arr = array_reverse($arr); $last = array_shift($arr); //Shift takes out the first element, but we reversed it, so it's last. $counter = 1; foreach ($arr as $result) { if ($result != $last) break; $counter++; } echo $counter;

preferences:
34.8 ms | 402 KiB | 5 Q