in PHP by
Q:
what is the difference between for and foreach?

► Click here to show 1 Answer

0 votes
by

for is expressed as follows:

for (expr1; expr2; expr3)

statement

The first expression is executed once at the beginning. In each iteration, expr2 is evaluated. If it is TRUE, the loop continues, and the statements inside for are executed. If it evaluates to FALSE, the execution of the loop ends. expr3 is tested at the end of each iteration.

However, foreach provides an easy way to iterate over arrays, and it is only used with arrays and objects.

Loan/Mortgage
Learn More with Madanswer

Related questions

0 votes
asked Jun 23, 2019 in PHP by SakshiSharma
...