Definitions



1112020

1112020

Even though I defined this number twice as two different values the file/code will always default to the first initial defintion of 1112020




Variables



Variable names are case sensitive - $userName is not the same as $username.

Variable names must start with $ and are alpha-numeric only OR use the underscore in their names.

Variable names should NOT commence with a number after the string symbol e.g. NO variable like $4ever.

Variable names should be meaningful.

Giving a value to a variable is known as assigning a value to it.

Assigning an initial value to a variable when declaring it is known as initializing the variable. This is not mandatory in PHP. However, it is considered bad practice not to do so as it can lead to unexpected behavior in the script.

Se we can initialise x as = 5. Then we can display that with echo $x

5

If we enclose a variable name in double quotation marks, the echo statement does not echo the variable name literally. Instead, it replaces the name with the value of that variable and echoes the value. For instance, if we write the following two version of code we get...

The value is $x. (because it was single quotes)

The value is 5 (because it was double quotes).

So, single quotes are literal and double quotes are expressive of the variable




Basic Data Types - int - float - bool



int refers to integers which are whole numbers with no decimal parts.

float refers to floating-point numbers which are numbers with decimal parts or in exponential form.

bool refers to affirmative or negative responses and is not case senstitive e.g. true, TRUE & True are all the same.

So, $x = 5 is an integer - $y = 2.1 is a float and $z = true is a boolean statement

To verify the data type of a variable, we can use a built-in function called var_dump(). This function requires us to provide the variable name and gives us the data type and value of the variable.

int(5)

float(2.1)

bool(true)




Basic Data Types - int - float - bool



Type Casting is the act of giving an integer a type.