From the course: PHP for WordPress
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Solution: Loop through an array of information
From the course: PHP for WordPress
Solution: Loop through an array of information
(upbeat music) - [Instructor] All right, let's go through the solution to the last challenge. You can see we have the array on screen here. So let's start. Of course, we want to use a foreach loop for this task because we have an associative array. So I'm going to say for each TMNT as and then we have the turtle's name and a list of attributes. So I'm going to say turtle, arrow, and then I'll say atts for the attributes. So the first thing we want to do is print the turtle's name in bold. Since we can use HTML embedded directly into our PHP. I'm going to say echo P, B for bold, then I'll say turtle, then I'll say colon end B, and then a space. The space is important. Remember that we need to explicitly state any spaces we want in our PHP code. Now we want a comma separated list of the attributes, so we'll actually need another foreach loop here foreach atts as I'll just say attr for attribute and then we'll echo the attributes. I'll say echo attr comma space. After that foreach loop…
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)
-
-
-