|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
PHP
DETAILS
Question: what is the difference between for and foreach?
Answer: for is expressed as follows:
for (expr1; expr2; expr3)
statement
The first expression is executed once at the beginning. In each iteration, expr2 is evaluated. If it is TRUE, the loop continues and the statements inside for are executed. If it evaluates to FALSE, the execution of the loop ends. expr3 is tested at the end of each iteration.
However, foreach provides an easy way to iterate over arrays and it is only used with arrays and objects.
|
|
|
Category |
PHP Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7808 users |
Added on |
5/3/2016 |
Views |
70708 |
Rate it! |
|
|
Question:
what is the difference between for and foreach?
Answer:
for is expressed as follows:
for (expr1; expr2; expr3)
statement
The first expression is executed once at the beginning. In each iteration, expr2 is evaluated. If it is TRUE, the loop continues and the statements inside for are executed. If it evaluates to FALSE, the execution of the loop ends. expr3 is tested at the end of each iteration.
However, foreach provides an easy way to iterate over arrays and it is only used with arrays and objects. Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What is the difference between the functions strstr() and stristr()?
|
View Answer
|
|
What are the two main string operators?
|
View Answer
|
|
What does $_SERVER means?
|
View Answer
|
|
What is faster?
|
View Answer
|
|
How is it possible to cast types in PHP?
|
View Answer
|
|
What is the most convenient hashing method to be used to hash passwords?
|
View Answer
|
|
what is the static variable in function useful for?
|
View Answer
|
|
What does the function get_magic_quotes_gpc() means?
|
View Answer
|
|
How can we check the value of a given variable is alphanumeric?
|
View Answer
|
|
How can we connect to a MySQL database from a PHP script?
|
View Answer
|
|
What is a cookie , explaing by code ?
|
View Answer
|
|
What does the URI used as an XML namespace name point to?
|
View Answer
|
|
Can I resolve the URI used as an XML namespace name?
|
View Answer
|
|
What are the valid values for xlink:actuate and xlink:show?
|
View Answer
|
|
How do you pass a variable by value?
|
View Answer
|
|
How To Create a Table?
|
View Answer
|
|
What are the different tables present in MySQL? Which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10))?
|
View Answer
|
|
Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?
|
View Answer
|
|
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?
|
View Answer
|
|
How can I execute a PHP script using command line?
|
View Answer
|