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 is a controller in programming?
List some sorting functions in php?
What is a substring in php?
What is the use of isset() in php?
What is final in php?
What is if isset ($_ post submit )) in php?
Explain what are the different errors in php?
Can php run without apache?
How does php work with apache?
I am writing an application in php that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with php?
What is session expiry?
What is the use of mysql_real_escape_string() function?
What is a composer in PHP?
how to detect a mobile device using php
How does one prevent the following warning ‘warning: cannot modify header information – headers already sent' and why does it occur in the first place?