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

What is the difference between mysql_fetch_array() and mysql_fetch_assoc()?

744


What is the use of Php variables?

794


What is the alternative structure for control structures?

820


What is cakephp framework?

751


What is phpsessid?

717


How send email in php?

725


How to run the interactive php shell from the command line interface?

785


What are magic constants in php?

783


Tell me what the difference between the 'bitwise and' operator and the 'logical and' operator?

728


What is exception handling in php?

1345


What sized websites have you worked on in the past?

756


How does firefox manage cookies?

764


Tell me what sized websites have you worked on in the past?

710


Why namespace is used in php?

744


What does $globals means?

702