Internee PHP Developer Question:
Download Questions PDF

Explain me what is the difference between for and foreach?


for is expressed as follows:

for (expr1; expr2; expr3)


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.

Download Internee PHP Developer Interview Questions And Answers PDF

Previous QuestionNext Question
Tell me is it possible to destroy a cookie?Tell me what is the differences between $a != $b and $a !== $b?