PHP Basic Part
Basic instructions for PHP output text: Echo and print.
Echo and the Print the Difference
ECHO is a PHP statement, print and Print_r are functions, the statement does not return a value, the function can have a return value (even if it is not used)
echo outputs one or more strings.
Print only prints out values for simple type variables (such as int,string)
Print_r can print out values for complex type variables (such as arrays, objects)
The difference between Var_dump and Print_r
Var_dump returns the type and value of the expression, and print_r only returns the result, which is easier to read than the debug code using Var_dump.
Variable
Variables are used to store values, such as numbers, text strings, or arrays. All variables in PHP start with the $ symbol.
The PHP variable name is case sensitive!
PHP has three different scope of variables:
Local (partial)
Global (globally)
Static (statically)
Variables declared outside the function have Global scope and can only be accessed outside of the function.
Variables declared inside a function have a local scope and can only be accessed inside the function.
The global keyword is used to access variables within the function.
PHP Learning Note 1