Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>First Steps Into PHP</title>
- </head>
- <body>
- <form>
- X: <input type="text" name="num1" />
- Y: <input type="text" name="num2" />
- Z: <input type="text" name="num3" />
- <input type="submit" />
- </form>
- <?php
- if (isset($_GET['num1']) && isset($_GET['num2']) && isset($_GET['num3'])){
- $n1 = intval($_GET['num1']);
- $n2 = intval($_GET['num2']);
- $n3 =intval($_GET['num3']);
- $numbers = [$n1, $n2, $n3];
- function count_negatives(array $numbers){
- $i = 0;
- foreach ($numbers as $x){
- if ($x < 0){
- $i++;
- }
- }
- return $i;
- }
- if (count_negatives($numbers) % 2 == 0 ){
- echo "Positive";
- }
- if (count_negatives($numbers) % 2 != 0 && in_array("0", $numbers, false)){
- echo "Negative";
- }
- if (in_array("0", $numbers, true)){
- echo "Positive";
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement