php foreach() keyword

PHP is_object() Function

In this article, you will learn how to create a foreach loop in PHP. The foreach keyword is used to create foreach loops, which loops through a block of code for each element in an array.

what is the syntax of the FOREACH() function in php?


examples of the FOREACH() function

Example 1. In this example, we close a foreach loop block.

$cars = ["Ford", "Volvo", "BMW"];
foreach($cars as $car) {
  echo "$car <br>";

Example 2. In this example, we Print keys and values from an associative array.

$people = [
  "Peter" => "35",
  "Ben" => "37",
  "Joe" => "43"

foreach($people as $person => $age) {
  echo "$person is $age years old";
  echo "<br>";
PHP is_object() Function
en English
Scroll to Top