what is the diffrence between for and foreach?

Answer Posted / p parimi

For can be used to run statements for a fixed number of
times, foreach can be used to run statements for dynamically
generated arrays(may be result of database query).We can
also used for loop for dynamically generated array(may be
result of database query) but foreach is the ideal way to
iterate dynamic array. The reason behind this, we don't know
the index of array as it may be associate result from
database query. So if we use foreach than it will iterate
the result one by one.

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me what is needed to be able to use image function?

764


Is php better than java?

762


What is new static in php?

728


What is mean tnq

1301


Explain mysql_error().

768


Write a program to show the joining of two strings in php?

749


What is empty php?

756


Name some of the popular frameworks in php.

755


How to pass variables and data from php to javascript?

750


What is http get and post?

746


Is php 7.0 stable?

702


How to remove values saved in the current session?

762


What is $globals php?

766


How to remove leading and trailing spaces from user input values in php?

765


How can you create a session in php?

760