PHP For Beginners - Lesson 3


1. PHP is case-sensitive. This means that the combination of uppercase and lowercase characters used in variables, objects, and function names is important (for example, $todaysdate is a different variable to $TodaysDate).
2. Any combination of spaces, tabs, linefeeds, and some other non-alphanumeric or punctuation characters is known as whitespace.
3. PHP generally ignores whitespace characters that appear outside of strings—whitespace within strings is stored and acted upon, though.
4. A numeric variable is a container for a number, which allows you to address the value using a name (for example, $age = 32;).
5. A string variable is a container for a sequence of characters, which can be addressed using a name (for example: $name = 'Albert Einstein';).
6. You can include quotation marks within a string (regardless of whether or not the same type is used to contain the string) by escaping them with the \ escape character, which can also be used to insert special characters (for example, $mystring = "He said, \"Hello\"\n" ;—which also includes a linefeed at the end).
7. A heredoc string is one that is not enclosed in any type of quotation mark. Instead, a token is used to denote the string’s start and end, and it is commonly used in conjunction with an echo statement or string assignment. The tokens are generally given a preceding underline character to help them stand out (although not required), and the closing token must appear at the very start of a new line (with no indentation and no spaces or tabs before or after the semicolon).
8. PHP variables do not necessarily retain the type they are initially assigned, because if an operation is performed on them that makes better sense if the content were of a different type, then PHP will change the type. Therefore, a string containing all digits is turned into a number by PHP if a mathematical operation is performed on it—for example, the following will output the number 1235, even though $n is initially a string: $n = '1234'; $n = $n + 1; echo $n;.
9. To force PHP to store a certain type of value in a variable, you can use a casting keyword such as (int) or (string). An example would be $n = (int) '1234'; or $s = (string) (12 * 34);.
10. In PHP, to display the values of variables within a string, you do not need to break the string into smaller parts and then use the concatenation operator to splice the parts and variables together (as you must in some languages). Instead, just enclose the string in double quotation marks (not single quotes) and then drop the variable names right in where they are needed (for example, echo "Hello $name, you have previously visited on $times occasions.";).

PHP For Beginners - Lesson 3

No comments:

Post a Comment