Which of the following are true about the foreach loop in PHP?

  • The foreach loop is used exclusively for arrays
  • The foreach loop can only access the values of an array
  • The foreach loop can access both the keys and values of an array
  • The foreach loop is not a valid construct in PHP
The correct option is: "The foreach loop can access both the keys and values of an array." In PHP, the foreach loop allows you to iterate over each element in an array and access both the keys and values of the elements. During each iteration, you can use the "key" variable to access the key/index of the current element, and the "value" variable to access the value of the element. This makes the foreach loop a versatile construct for working with arrays. Learn more: https://www.php.net/manual/en/control-structures.foreach.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *