From the course: PHP for Web Designers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Inspecting an array's elements - PHP Tutorial
From the course: PHP for Web Designers
Inspecting an array's elements
Arrays are widely used in PHP. The input from a form is stored as an array. At each row of a database search result is an array. In the file that I've got open here, the array elements are hard-coded above the doc type, but you often don't know in advance what an array contains or how it's structured. Thankfully PHP has a built in function that let's you examine the contents and structure of an array. Its an essential tool used in testing and it helps explain how PHP sees arrays internally making it easier for you to understand how to get the information you want. To display the contents of an array you pass the array variable as an argument to a function called print_r. And so what I'm going to do is in the body of this page, I'm going to add a couple of pre tags. Adding the pre tags makes it easier to see the output of print_r in a browser. And between those pre tags I'm going to add my PHP block and then, between there, will be print_r, and the argument will be the name of the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Storing multiple values in a variable as an array4m 28s
-
(Locked)
Inspecting an array's elements4m 13s
-
(Locked)
Challenge: Inserting the appropriate alt text1m 27s
-
(Locked)
Solution: Inserting the appropriate alt text5m 26s
-
(Locked)
Displaying an array as a comma-separated list3m 13s
-
(Locked)
Looping through an array's values7m 17s
-
(Locked)
Labeling array elements7m 21s
-
(Locked)
Looping through an array's labels and values5m 29s
-
Finding if a value exists in an array3m 51s
-
(Locked)
Challenge: Displaying a seasonal feature3m 6s
-
(Locked)
Solution: Displaying a seasonal feature8m 30s
-
(Locked)
-
-
-
-