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

How can we determine whether a php variable is an instantiated object of a certain class?

767


How to write php function in html onclick?

716


Explain how you can update memcached when you make changes to php?

817


What is the function of trim?

728


What is the difference between characters 34 and x34?

842


What is full form of php? Who is the father or inventor of php?

785


Is php a web server?

772


What are differences between PECL and PEAR?

739


How can we access the data sent through the url with the get method?

837


What is string function sql?

735


What is mysqli_real_escape_string?

767


What is the use of imagetypes() method?

745


Tell me how can we check the value of a given variable is alphanumeric?

759


Are php short tags acceptable to use?

749


Explain object-oriented methodology in php?

789