MOTOSHARE 🚗🏍️

Rent Bikes & Cars Directly from Owners

Motoshare connects vehicle owners with people who need bikes and cars on rent. Owners earn from idle vehicles, and renters get flexible ride options.

Visit Motoshare

Tutorial for “For each” loop

php

What is For each Loops?

Use the for each loops to cycle through arrays. At each pass, the value of the current array element is set to $value. In the next pass, the array pointer is moved one by one. The for each loop is only used to loop around each key/values pair in an array. Only arrays are supported.

Syntax:-

foreach ($array as $value) {
  code to be executed;
}

Here are some of the Foreach Loops:-

  • “foreach(…){…}” is the foreach php loop block code
  • “$array_data” is the array variable to be looped through
  • “$array_value “ is the temporary variable that holds the current array item values.
  • “block of code…” is the piece of code that operates on the array values
PHP Loop and  Control Structures

Example1:-

Output:-

Example2:-

Output:-

Ashwani Kumar
Latest posts by Ashwani Kumar (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x