<?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' );
You have javascript disabled. You will not be able to edit any code.