1. Three types of expressions for strings:
(1) Double quotation marks
(2) Single quotation mark
(3) Angle brackets
$s = <<<a
<div style= "width:500px; height:100px; Background-color:red "></div>
A must be written shelf, one line alone
2, three kinds of error prompt way
Notice: Alert Warning: Warning Error: Wrong
3, ternary operator
(1) $a = 10;
$b = 10;
echo $a = = $b? " OK ":" NO "; -----------OK
(2) $sex = true;
echo $sex? " Male ":" Female "; ----------Male
4. Statements
(1) Branch statements
if () {}
if () {}else{}
if () {}else if () {}
if () {if () {}}
(2) Swich statement
Switch ($a)
{
Case 1:
echo "1111";
Break
Case 2:
echo "2222";
Break
Case 3:
echo "3333";
Break
Default
echo "4444";
}
(3) Loop statement
for ($i =0; $i <10; $i + +)
{
echo "{$i}<br>";
}
(4) While statement (for dead loops, or output specific values)
$a = 0;
while ($a <10)
{
$a + +;
echo "{$a}<br>";
}*/
5. Functions
Four elements: return type function name parameter list function body
(1) Simple function
function Test ()
{
echo "Simple function";
}
Test ();
(2) function with parameters
function Test ($a)
{
echo $a;
}
Test ("Hello"); -------------Hello.
(2) function with return value
function Test ()
{
return "Test";
}
echo Test ();------------Output Testing
(4) Function of variable parameters
function Test ()
{
$arr = Func_get_args ();//Get all parameters, return array
$sum = 0;
for ($i =0; $i <count ($arr); $i + +)
{
$sum = $sum + $arr [$i];
}
return $sum;
}
echo Test (1,2,3,4,5,6,7,8,9,10);
Note: Strongly typed language functions
Public return type (void/int/string.bool) Say (int a)
{
}
6. Generate Random Numbers
echo rand (0,10); ---------- generated by seed, the default seed is the current date
7. Date and Time
(1) Echo time (),-------------the number of seconds that have been accumulated in 1970, that is, the timestamp
(2) Echo date ("Y year M D Day H:i:s");
Y year M month D Day h 24 hour hour H 12 Hour system I minute s seconds
(3) Echo strtotime ("2017-4-14 14:52:52"); Convert a string to a timestamp
Examples:
1.
$a = 10;
$b = 3;
echo $a/$b; ------3.333333
depends on what type it is (the decimal type is the decimal type; the integer is the integral type)
2.
$a = 1;
$b = $a + +; equivalent to $b= $a; $a = $a +1 first assignment after Operation
echo $b;-----1
3.
$a = 1;
$b = + + $a; equivalent to $a= $a +1; $b = $a; Assign value after first operation
echo $b;-----2
Basic knowledge of PHP (ii)---2017-04-14