what is the diffrence between for and foreach?

Answer Posted / anuradha

foreach sort of asbtracts away some of the complexity and is
usually easier. I use this whenever I don't need to know the
numeral index of the array or $key => $value won't provide
me with it.

for is the older C style where you must first perform a
count() so you know how many iterations the loop requires.
It is useful when you need to know the index, or to count
backwards or step through in different groups.

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is age nominal or ordinal?

509


What does it mean when it says the csrf token is invalid?

496


Write a program to get second highest number in an array using php?

527


What is difference between Method overriding and overloading in PHP?

543


What is move_uploaded_file in php?

543






What is the difference between php and java?

518


What is difference between get and post in php?

602


How to set cookies?

551


What are the special characters you need to escape in double-quoted stings?

535


Which is faster for or foreach?

506


What is include in php?

539


What is the difference between Split and Explode in PHP?

567


Tell me whether it is possible to share a single instance of a memcache between multiple php projects?

537


Explain about the connective abilities of the PHP?

598


Name some of the functions in php.

496