3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['1', '15', '2','10', 4]; foreach ($array as $v) { if (!isset($max1)) { $max1 = $v; } elseif ($max1 < $v) { $max2 = $max1; $max1 = $v; } elseif (!isset($max2) || $max2 < $v) { $max2 = $v; } } var_dump( $max1 ?? 'Never declared', $max2 ?? 'Never declared' );

preferences:
75.19 ms | 840 KiB | 5 Q