From the course: PHP for WordPress
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Loops
- [Instructor] Loops are a fundamental part of PHP and WordPress specifically. In fact, the important portion of WordPress code is actually called the loop. And we'll look at two types of loops: while loops and foreach loops. But first, let's look at what they are. An if statement will execute a piece of code once if a condition is true, but loops will continue to execute a piece of code until the condition becomes false. There are lots of applications for loops like enumerating, performing repetitive math, and listing a set of items. But in WordPress, loops are most often used to process arrays. Now, before we get into actual code examples, let's look at the structure of each. While loops will do something while a condition is true. And these are general purpose loops used for math, enumeration, or anything that you can think of. Foreach loops are loops that do something for each item in a list and these are used to process arrays. The syntax for a while loop is this: while…
Contents
-
-
-
-
(Locked)
Comparison operators and the truth4m 26s
-
(Locked)
Logical operators5m 55s
-
(Locked)
Creating if/else statements6m 53s
-
Switch and match statements4m 28s
-
(Locked)
Conditional tags in WordPress1m 19s
-
(Locked)
Loops7m 56s
-
(Locked)
The Loop in WordPress2m 54s
-
(Locked)
Challenge: Loop through an array of information1m 12s
-
(Locked)
Solution: Loop through an array of information5m 28s
-
(Locked)
-
-
-