课程: PHP for WordPress (2020)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using arrays

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…

内容