what is foreach loop in PHP?

foreach looping in PHP ? texpoundsofttechsolution h foreach looping in PHP ?

Foreach loop in php

foreach loop in php ? The foreach looping is the advance loop to access all the values of the array. The foreach loop works only on arrays. It can also be used to iterate over objects. Syntax of foreach loop :-
foreach( $arrayname as $element ) {
    // your php code
Here is an example for easy understanding of foreach loop. By this example you will understand when to use foreach loop and how foreach loop work in php.
$fruits = array("apple","banana","grapes","orange","papaya");
foreach ( $fruits as $fruit )
echo  "$fruit<br />";
Output of the above code.
The foreach looping is also use to access each key/value pair from an array. With the help of foreach loop we can also access in key value format of array data. Key/value pair example

$subject = array("hindi" => "87", "English" => "84", "Maths" => "85", "Chemistry" => "81", "Physics" => "79");

foreach($subject as $x => $value) {
    echo "$x = $value <br>";
hindi = 87
English = 84
Maths = 85
Chemistry = 81
Physics = 79