From the course: PHP for WordPress (2020)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using arrays - PHP Tutorial
From the course: PHP for WordPress (2020)
Using arrays
- [Instructor] Arrays are a bit different from the rest of our variables. Arrays act as key-value pairs that essentially function as a set of variables. So let's say we want a collection of colors like we have on the screen here. We could store each color in a variable where color1 gets red, color2 gets green, et cetera but that can get cumbersome and hard to manage and depending on the size of the data, inefficient for PHP to run. So instead, we would use an array. We can create a single variable called colors and then use the array keyword. When we add an array, we would use the keyword array and then an opening parentheses. Then we would add each color in a comma-separated list. So we would write single quote red and single quote comma green comma blue comma yellow. And then the closing parentheses and the semicolon. Now, we can reference each element in the array based on an index. But to better…
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
-
-
-
What is PHP?2m 1s
-
(Locked)
Printing information3m 15s
-
(Locked)
What are variables?6m
-
(Locked)
Strings in PHP5m 57s
-
(Locked)
Using arrays7m 59s
-
(Locked)
Arithmetic operators and math in PHP4m 38s
-
(Locked)
Challenge: Perform a mathematic operation and store it1m 14s
-
(Locked)
Solution: Perform a mathematic operation and store it3m 33s
-
-
-
-
-