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,823
Replies
17
Views
5,256
Replies
1
Views
1,754
Replies
3
Views
2,017
Newer threads
Replies
0
Views
6,279
Replies
1
Views
2,021
Replies
3
Views
1,251
Replies
12
Views
2,132
Latest threads
Replies
2
Views
105
Replies
1
Views
186
Replies
6
Views
402
Replies
11
Views
544
Replies
2
Views
236
Recommended threads
Replies
0
Views
1,351
Replies
1
Views
6,184
Replies
13
Views
5,785
Replies
6
Views
2,919
Replies
2
Views
13,622

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