Variables: 1. Variable declaration: Starts with $, consists of numbers and letters, numbers cannot be in front.
- Output: Echo//Output to page, cannot output complex type
- Print_r ()//can print complex types
- var_dump//can print detailed information about complex types
- Print_r and Var_dump are mainly used for commissioning
- PHP is also a weakly typed language
3. Arrays
- A. Create array $arr=array (1, "a", 3);//elements can be of different types
-
Another form of array initialization
$arr [] = ' Hello ';
$arr [] = ' Hi ';
$arr [] = ' Nihao ';
- B. Two-dimensional array:
Two-dimensional arrays
$arr = Array (
Array (123,456,789),
Array (111,222,333),
Array (32423,22322,33233),
Array (213123,234324,345345)
// );
Another way to initialize a two-dimensional array
$arr [] = array (123,456,789);
$arr [] = array (123,456,789);
$arr [] = array (2342,456,78234239);
$arr [] = array (123,456,789);
$arr [] = array (123,456,789);
- C. Two-D arrays
-
Associative arrays
$arr = Array (' attr1 ' = ' hello ', ' attr2 ' = ' Hi ', ' attr3 ' = ' Nihao ');
$arr [] = ' Tom ';
$arr [] = ' Jerry ';
echo count ($arr); 5ATTR1-----Hello
ATTR2-----Hi
ATTR3-----Nihao
0-----Tom
1-----Jerry
- D. Array method://php Built-in function count (), the function is to calculate the length of the array
-
The function of the Array_push () function is to append an element to the end of the array
Array_push ($arr, 5);
Array_push ($arr, ' hello ');
The action of the Array_pop () function is to take out the last element of the array
$ret = Array_pop ($arr);
4.//traversing an array
- The $k here refers to the index of the array, $v refers to the index corresponding to the value
foreach ($arr as $k = = $v) {
Echo $k;
Echo ' <br> ';
Echo $v;
}
5. Use of string concatenation
- The string concatenation used in PHP is.
- PHP has a difference between single and double quotes: double quotes parse the variables in the string, but single quotes do not
- $num = 123;
- $str = ' Hello ';
- echo $str. '---------- ----'. $num;
- echo ' Hello $num ';
- echo "Hello $num";
6. Functions
7. Garbled problem:
- The function of this sentence is to tell the browser to receive this page, as a Web page display and use UTF-8 encoding display
Header (' content-type:text/html; Charset=utf-8 ');
PHP Basic Syntax