foreach loop

PHP foreach loop works only on arrays and objects.
Array pointer is always incremented by one.

There are two syntaxes for foreach loop:

Syntax of PHP foreach loop

OR

 

Example using value

Output:

 

Example using key

Output:

 

Example

Output:

Ankit Wasankar

Senior Java Developer
Java 11 | Microservices | Reactjs | SQL

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.