Variables

Variables are numbers, text, or other values that are being processed in code. Let's say a user runs a program that asks for their name as input and prints "Hello (your name)" to the screen. When you enter your name, the program will store it in memory as binary values that represent the text.

Setting a variable in code looks like this:

$name = "Susan";

The $ means this is a variable called name. The = sets it to the value within the quotes, and the ; terminates the line.

Now the program can use the variable, for example to pass into a print function for the output.

print($name);

 

Topics