Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>First Steps Into PHP</title>
  6.  
  7. </head>
  8. <body>
  9. <form>
  10. X: <input type="text" name="num1" />
  11. Y: <input type="text" name="num2" />
  12. Z: <input type="text" name="num3" />
  13. <input type="submit" />
  14. </form>
  15. <?php
  16. if (isset($_GET['num1']) && isset($_GET['num2']) && isset($_GET['num3'])){
  17. $n1 = intval($_GET['num1']);
  18. $n2 = intval($_GET['num2']);
  19. $n3 =intval($_GET['num3']);
  20. $numbers = [$n1, $n2, $n3];
  21.  
  22.  
  23. function count_negatives(array $numbers){
  24. $i = 0;
  25. foreach ($numbers as $x){
  26. if ($x < 0){
  27. $i++;
  28. }
  29. }
  30. return $i;
  31. }
  32. if (count_negatives($numbers) % 2 == 0 ){
  33. echo "Positive";
  34. }
  35. if (count_negatives($numbers) % 2 != 0 && in_array("0", $numbers, false)){
  36. echo "Negative";
  37. }
  38. if (in_array("0", $numbers, true)){
  39. echo "Positive";
  40. }
  41. }
  42. ?>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement