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' );
Output for 8.1.32 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(2) "15" string(2) "10"

preferences:
56.53 ms | 840 KiB | 4 Q