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
What are examples of dependent variables?
How be the result set of mysql handled in php?
How can we access the data sent through the url with the get method?
What are the php functions?
Why die is used in php?
When you want to show some part of a text displayed on an html page in red font color? What different possibilities are there to do this? What are the advantages/disadvantages of these methods?
Where can I learn php?
Is laravel frontend or backend?
What is the use of imagetypes() method?
What is a model in php?
What is the timeout period on session values?
What is the difference between print() and echo()?
What is the difference between the include() and require() functions?
What is the best way to change the key without changing the value of a php array element?
What is the difference between htmlentities() and htmlspecialchars()?