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 nan in php?

529


What is a model in php?

535


How do you remove whitespace from the beginning and end of a $string variable?

498


Tell me how stop the execution of a php scrip?

524


How to access a specific character in a string using php?

513






What does $_env means?

549


What are the types of variables in php?

537


What is the meaning of a final class and a final method?

532


What advance thing in php7?

519


Does php class need constructor?

481


How to close a session properly?

524


What is php data type?

519


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

499


How we get ip address of client, previous reference page etc?

562


Tell me what is the difference between get and post?

475