The new PHP file must be placed in the WWW folder under the Wamp installation directory. If you get somewhere else, PHP will not work and an error is displayed.
<? php?> //How to embed PHP
<? php//The beginning of the way to embed PHP //php single-line comment syntax /* php multiline comment syntax */ // output syntax//echo "Hello"; the most common is Echo,echo followed by a string. The principle is to use PHP code in the source code to play Hello, and then through the browser parsing out. echo "World", "dhakj"; You can output multiple strings, separated by commas. <br/> (The contents of the Web page), instead of \ n, is required for line breaks. print "AAA"; can also be output, but only one string//print_r () is output; An array is written in parentheses to print the group//var_dump (); can also be output, but the output is variable and type, which is most powerful relative to the output above. Variable definition//data type, weakly typed language, defined without the need to define the variable type, automatic turn. $a = "Hello", defined as $ A, and all variables are the beginning of the $ symbol. Even for the For Loop for ($i =1; $i <10; $i + +) also add $.
//$hello = "World"; echo $ $a; Variable variable, the result of the output is world. Parse $a=hello First, then parse $hello=world. Type conversion//$a = 6; $b = (string) $a; Type conversions, converting integers to strings. (string) $a means converting an integer A to a data type of string.
Settype ($a, "string"); Another way
Var_dump ($a);
Operators and expressions, mathematical operators (+ 、-、 *,/) and JS inside the same.
$a = 6;
$b = 7;
Echo $a + $b
$c = $a = = $b;
Var_dump ($c);
Concatenation of strings
$a = "Hello";
$b = "World";
$c = $a. $b; PHP inside the concatenation of strings with a dot (.) Other languages are used by the +.
Echo $c; The output is HelloWorld
$a = 8;
@ $c = $a/$b; The error suppressor, which masks the wrong information. Generally not used, there is the wrong information to correct instead of shielding off.
Echo $c;
The error message inside PHP can be masked with @. Notice and warning can be blocked off.
Notice: Reminders
Warning: Warning
Error: Wrong
Ternary operator, which is equivalent to a simple if.
$a = 4;
$b = 5;
echo $a = = $b? " Equal ":" Not Equal "; Equality outputs "equal", unequal outputs "unequal", and the middle is separated by colons.
Statement
order, executed in order.
$a = 5;
$b = 6;
Branch, the first is if, and the second is switch
/ *if ($a = = $b)
{
echo "equal";
}
Else
{
echo "Unequal";
}
Switch ($a)
{Case 4:
echo "4444";
Break
Case 5:
echo "55555";
Break
Case 6:
echo "66667";
Break
Default
echo "000000";
}*/
//loops, for loops, while loops, Do,while loops
/ *For ($a =0; $a <10; $a + +)
{
echo $a;
}
while (true)//to judge the condition before execution
{
echo "AAA";
}
Do//Execute the statement first, then look at the condition.
{
}
while ()*/?>
10.21 a.m. PHP Basics