3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if(isset($_POST["submit"])) { // if submitted assign variables values $low = $_POST["lowNum"]; $highLimit = $_POST["highNum"]; $countLines = 0; $sum_ev = 0; $sum_od = 0; $sum_prm = 0; $constant_prm; } // Function for Prime Numbers Queries function primePrint() { echo "#==================Prime Numbers=========================#"; global $low, $highLimit, $lowLimit, $countLines, $sum_prm; for( $lowLimit = $low; $lowLimit <= $highLimit; $lowLimit++ ) { for( $constant_prm = 2; $constant_prm <= $lowLimit - 1; $constant_prm++ ) { if( $lowLimit % $constant_prm == 0 ) { break; } } if( $constant_prm == $lowLimit ) { $countLines++; echo "<br>"."Prime Number ".$countLines." : ".$lowLimit; $sum_prm = $sum_prm + $lowLimit; } } echo "<br>"; echo "<strong>Total Prime Numbers Count is : </strong>".$countLines; echo "<br>"; echo "<strong>Total Prime Numbers Summation is : </strong>".$sum_prm; echo "<br>"; echo "#=====================================================#"; } // Function for Even Numbers Queries function evenPrint() { echo "#==================Even Numbers=========================#"; global $low, $highLimit, $lowLimit, $countLines, $sum_ev; for( $lowLimit = $low; $lowLimit <= $highLimit; $lowLimit++ ) { if( $lowLimit % 2 == 0 ) { $countLines++; echo "<br>"."Even Number ".$countLines." : ".$lowLimit; $sum_ev = $sum_ev + $lowLimit; } } echo "<br>"; echo "<strong>Total Even Numbers Count is : </strong>".$countLines; echo "<br>"; echo "<strong>Total Even Numbers Summation is : </strong>".$sum_ev; echo "<br>"; echo "#=====================================================#"; } // Function for Odd Numbers Queries function oddPrint() { echo "#==================Odd Numbers=========================#"; global $low, $highLimit, $lowLimit, $countLines, $sum_od; for( $lowLimit = $low, $countLines = 0; $lowLimit <= $highLimit; $lowLimit++ ) { if( $lowLimit % 2 > 0 ) { $countLines++; echo "<br>"."Odd Number ".$countLines." : ".$lowLimit; $sum_od = $sum_od + $lowLimit; } } echo "<br>"; echo "<strong>Total Odd Numbers Count is : </strong>".$countLines; echo "<br>"; echo "<strong>Total Odd Numbers Summation is : </strong>".$sum_od; echo "<br>"; echo "#=====================================================#"; } ?> <?php // Form to get inputs echo "<form action='assignment-2.php' method='post'>"; echo "Enter the range of numbers to find prime, even and odd numbers >>"; echo "<br>"; echo "<br>"; echo "Enter the lower range number : "."<input type='text' name='lowNum'>"; echo "<br>"; echo "Enter the higher range number : "."<input type='text' name='highNum'>"; echo "<br>"; echo "<input type='submit' name='submit' value='Submit'>"; echo "</form>"; ?> <?php echo "<br>"; if(isset($_POST["submit"])) { // if submitted then call the functions primePrint(); echo "<br>"; evenPrint(); echo "<br>"; oddPrint(); } ?>
Output for 4.3.0 - 7.1.0
<form action='assignment-2.php' method='post'>Enter the range of numbers to find prime, even and odd numbers >><br><br>Enter the lower range number : <input type='text' name='lowNum'><br>Enter the higher range number : <input type='text' name='highNum'><br><input type='submit' name='submit' value='Submit'></form> <br>