0 votes
in PHP by
what is the difference between for and foreach?

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.

Related questions

+1 vote
asked Jun 23, 2019 in PHP by SakshiSharma
0 votes
asked Jun 22, 2019 in PHP by SakshiSharma
...