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
Is null or empty c#?
What is a path Traversal?
What is php in simple words?
What are arguments in php?
How can we set and destroy the cookie in php?
How to randomly retrieve a value from an array?
What good is polymorphism?
Is uploaded file php?
What are the environmental variables?
What are the advantages of oops in php?
What is the function in PHP do not return a timestamp?
Difference between array_combine and array_merge?
What is $globals php?
How can we define a variable accessible in functions of a php script?
What is the main function of php?