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
Which function would you use to replace a record in a database in php?
What is putenv?
Write a program using while loop?
in PHP for pdf which library used?
Does csrf token change?
Is php used for frontend or backend?
How are variables declared in php?
How to return ascii value of character in php?
What is difference between single quotes and double quotes in php?
Tell me what are the different types of errors in php?
What is the maximum size of a database in mysql?
How can we know the total number of elements of Array?
What is the difference between == and === in php?
How to define a user function?
Explain preg_Match and preg_replace?