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,816
Replies
17
Views
5,250
Replies
1
Views
1,750
Replies
3
Views
2,012
Newer threads
Replies
0
Views
6,269
Replies
1
Views
2,013
Replies
3
Views
1,251
Replies
12
Views
2,129
Latest threads
Replies
1
Views
74
Replies
1
Views
172
Replies
4
Views
378
Replies
11
Views
522
Replies
2
Views
227
Recommended threads
Replies
8
Views
2,515
Replies
5
Views
2,832
Replies
0
Views
2,145
Replies
0
Views
2,321

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