Arrays 
Arrays
by Brad Hussey
Video Lecture 12 of 45
Not yet rated
Views: 863
Date Added: May 14, 2017

Lecture Description

Lecture 12: Arrays

Sometimes you'll want to store more than one value within your variables. With an array, you can do just that! Arrays allow you to store multiple values within a variable.

For example, I think moustaches are neat. There are many kinds of moustaches! Using individual variables, I can store each moustache in their own, like so:

$moustache1 = "Handlebar";

$moustache2 = "Salvador Dali";

$moustache3 = "Fu Manchu";

But, I'd like to keep things neat n' tidy and have all my moustaches in a single variable. So I'll use an array, like so:

$moustaches= array("Handlebar", "Salvador Dali", "Fu Manchu");

Each value is automatically assigned a "key" in the array, so we can grab a specific value when we need it. We'll touch on keys later, but by default, each value has a numeric key assigned to it.

So for example, "Handlebar" is 1, "Salvador Dali" is 2, and "Fu Manchu" is 3. Here's the catch though — the numbers start at 0, not 1. So, "Handlebar" is actually 0, etc.

If we want to grab a value out of an array and display it on our web page, we just reference the array and the key associated with the value we want to display, like so:

echo $moustaches[0]; // this will display "Handlebar"

echo $moustaches[1]; // this will display "Salvador Dali"

echo $moustaches[2]; // this will display "Fu Manchu"

DOWNLOAD COURSE FILES HERE
www.bradhussey.ca/download-php-course

Course Index

Course Description

This course is a Total Beginner's Guide to Coding Your Very Own Dynamic Websites with PHP, so you need no prior knowledge or experience — although it's a good idea that you know some HTML (my beginner's guide "Build a Website from Scratch with HTML & CSS" will get teach you everything you need to know).

So — why learn PHP? Well, PHP is a very powerful scripting language used by millions of websites. Some of the most popular websites and frameworks utilize PHP to build their dynamic websites. PHP works very well with HTML, and therefore will allow you to start coding dynamic websites quickly without having to learn some of the more complicated scripting languages out there.

Comments

There are no comments. Be the first to post one.
  Post comment as a guest user.
Click to login or register:
Your name:
Your email:
(will not appear)
Your comment:
(max. 1000 characters)
Are you human? (Sorry)