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,483
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,957
Replies
17
Views
5,393
Replies
1
Views
1,835
Replies
3
Views
2,098
Newer threads
Replies
0
Views
6,448
Replies
1
Views
2,106
Replies
3
Views
1,276
Replies
12
Views
2,168
Latest threads
Replies
1
Views
115
Replies
0
Views
126
Replies
0
Views
175
Replies
5
Views
443
Recommended threads
Replies
1
Views
2,544
Replies
9
Views
14,683
Replies
0
Views
2,242
Replies
13
Views
5,560
Replies
5
Views
4,183

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