what is the diffrence between for and foreach?

Answer Posted / tarsem kurra

foreach is used to iterate over arrays and for loop is used
to run statement for number of times and there is another
major difference is in foreach you want to execute statement
which comes from an database with id which is
autoincremented and you run for loop over it and suppose in
the mean time i delete 3rd rows i.e. 3rd id than what will
this loop stops working but not in foreach and foreach is
the faster than for loop..

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain me what is the importance of "method" attribute in a html form?

497


Tell me how to get the value of current session id?

503


Is php the same as html?

544


What is difference between variable declaration and variable definition?

495


What are the 3 types of sessions?

539






How can I convert ereg expressions to preg in php?

474


What is htaccess? Why do we use this and where?

490


How big is nvarchar max?

568


What is a controller in php?

549


How to access a Static Member of a Class in PHP?

509


What is 'float' property in css?

582


What is the use of die in php?

515


How a variable is declared in php?

507


What is the difference between javascript and php?

519


How to find a substring from a given string in php?

501