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,818
Replies
17
Views
5,251
Replies
1
Views
1,751
Replies
3
Views
2,013
Newer threads
Replies
0
Views
6,271
Replies
1
Views
2,013
Replies
3
Views
1,251
Replies
12
Views
2,129
Latest threads
Replies
1
Views
77
Replies
1
Views
174
Replies
4
Views
381
Replies
11
Views
523
Replies
2
Views
228
Recommended threads
Replies
3
Views
1,994
Replies
1
Views
3,407

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