fork download
  1. <?php
  2.  
  3. // Create an array of colors
  4. $colors = array("red", "green", "blue", "yellow");
  5.  
  6. // Loop through the array and print each color
  7. foreach ($colors as $color) {
  8. echo $color . "\n";
  9. }
  10.  
  11. // Check if the user's favorite color is in the array
  12. $favoriteColor = "green";
  13. if (in_array($favoriteColor, $colors)) {
  14. echo "Your favorite color is in the array!\n";
  15. } else {
  16. echo "Your favorite color is not in the array.\n";
  17. }
  18.  
  19. // Create a new array of numbers
  20. $numbers = array(1, 2, 3, 4, 5);
  21.  
  22. // Loop through the array and print each number
  23. for ($i = 0; $i < count($numbers); $i++) {
  24. echo $numbers[$i] . "\n";
  25. }
  26.  
  27. // Sort the array of numbers in ascending order
  28. sort($numbers);
  29.  
  30. // Loop through the array and print each number again
  31. foreach ($numbers as $number) {
  32. echo $number . "\n";
  33. }
  34.  
  35. ?>
Success #stdin #stdout 0.03s 25652KB
stdin
5 2
3 2
4 4
stdout
red
green
blue
yellow
Your favorite color is in the array!
1
2
3
4
5
1
2
3
4
5