Explain what is the difference between for and foreach?
Submitted by: Administratorfor 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.
Submitted by:
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.
Submitted by:
Read Online Junior Developer PHP Job Interview Questions And Answers
Top Junior Developer PHP Questions
☺ | Tell me how the result set of Mysql be handled in PHP? |
☺ | Tell me whether it is possible to share a single instance of a Memcache between multiple PHP projects? |
☺ | Do you know what does $GLOBALS means? |
☺ | Please explain is it possible to use COM component in PHP? |
☺ | Explain how can PHP and Javascript interact? |
Top Web Developer Categories
☺ | Bootstrap Interview Questions. |
☺ | Front End Web Developer Interview Questions. |
☺ | Typography Interview Questions. |
☺ | Laravel PHP Developer Interview Questions. |
☺ | Junior Developer PHP Interview Questions. |