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 time a dependent variable?
What is difference between static and constant in php?
Can php run without apache?
What is the use of "ksort" in php?
What is an anti csrf token?
Explain scalar type declarations in php7?
Why constructor is not overridden?
Does php have block scope?
Which is faster for or foreach php?
Which MySQL function would you use to select a database?
Where to put php files in apache server?
How to create a session? How to set a value in session? How to remove data from a session?
i m a B.E,passed out few yrs bak failed to find good job due to less marks now thinkin of a career as PHP developer. is it a lucarative field and wat r career prospects; hv heard dat initial salary is very less bout 6k also most jobs r contrct jobs.pls guide me need ur valuable advice.pls hellppp!! thnx..
Write a program using while loop in php?
Which is faster for or foreach?