Foreach vs While?

RufusBrewer

Member
Joined
Sep 18, 2013
Messages
54
Points
8
What's the advantage between the two functions?
I am learning PHP and wanting to display a list of things from mysql database, but I don't know what's the difference between Foreach and While PHP command and when should one function be used?
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,481
Points
113
Use while for database iteration. Use foreach for array iteration.
 

RufusBrewer

Member
Joined
Sep 18, 2013
Messages
54
Points
8
RufusBrewer
It is hard to understand this if I don't see any code examples or explaining what you were talking about.
Programming is more different from theory.
 

Jerome

New member
Joined
Jul 5, 2017
Messages
2
Points
0
Jerome
That is all you need, best answer.

However to get more into details php.net is the best source you will ever find for PHP.

I can't post links to php because I have not enought posts but go and checkout php.net

On the PHP website itself it is explained very well plus you will find good examples in the comments below.

Best regards
Jérôme
 
Older threads
Replies
5
Views
2,830
Replies
17
Views
5,260
Replies
1
Views
1,757
Replies
3
Views
2,021
Newer threads
Replies
0
Views
6,288
Replies
1
Views
2,028
Replies
3
Views
1,253
Replies
12
Views
2,133
Latest threads
Replies
1
Views
13
Replies
2
Views
129
Replies
1
Views
190
Replies
6
Views
439
Replies
11
Views
548
Recommended threads
Replies
5
Views
1,733
Replies
9
Views
2,003
Replies
0
Views
2,010
Replies
20
Views
10,936

Latest postsNew threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top