A string of 1 definitions
Use 0 or more characters enclosed in single or double quotation marks .
Single quotes:
there is no value for the parsed variable, capable of being escaped \ \ '
Double quotes:
the ability to parse the value of a variable can be escaped
The essence of Heredoc is to use double quotation marks to define large segments of text, but to write in another way.
The essence of Nowdoc is to use single quotation marks to define large segments of text, but to write in a different way.
A string can also be used as a series organized by multiple characters
Example:
2 string length
①,strlen
Grammar:
strlen ( variable )
Description
The number of bytes used to get a string
Support for ②, multibyte characters
The default letter holds a character in the 1 bytes occupied by any character living in .
However, for example: Kanji, a character may occupy multiple bytes, so PHP provides support for multibyte characters.
Support for multibyte characters needs to be turned on in PHP.ini .
after opening a multi-byte branch, we can use multibyte-character manipulation functions.
Mb_strlen ( variable, memory encoding )
3 string-related functions
①, Output function
Echo
Print
Print_r
Var_dump
②, finding and intercepting functions
Strstr (STR,SUBSTR)
Description
used to query substrings in the string str for the first occurrence of a substring Substr, and to intercept the last
STRRCHR (STR,SUBSTR)
Description
used to query substrings in string str for the last occurrence of a sub-string , and to intercept the last
Example:
③, find
Strpos (STR,SUBSTR)
Description
The position used to query substrings in the string str for the first occurrence of sub- str
STRrPOS (STR,SUBSTR)
Description
used to query substrings in the string str where the last occurrence of the sub- str
Example:
④, Split
Explode ( delimiter , str)
Description
Specifies the specified delimiter, splits the string str, and organizes each part into an array and returns
Example:
⑤, replace
Str_replace (Search,rep, str);
Description
in the string str , find the content represented by search and replace it with the content represented by Rep
⑥, uppercase and lowercase conversions
Strtolower ()
Strtoupper ()
Example:
⑦, removing specified characters
Trim (str", substr")
Description
used to remove substring substr on both sides of the string str .
SUBSTR can be omitted if omitted to indicate the removal of whitespace.
Example:
LTrim (str", substr");
RTrim (str", substr")
⑧,pathi NFO
Grammar:
PathInfo (Path", Option");
Description
Path is a string of file paths
The path information used to get a file ( file name, folder, file name, extension )
the option parameter is used to get the part specified in the path information
Example:
Example:
⑨,MD5 ()
Grammar:
MD5 (STR);
Description
used to encrypt the str string feed. the MD5 processing of strings of any length gets a string of length.
⑩,htmlspecialchars
Grammar:
Htmlspecialchars (str)
Description
used to convert the greater than sign less than sign in the string str to the corresponding character entity.
< < > >
Example:
Htmlspecialchars_decode (str)
Two-array preliminary 1 concept
An array is a collection of data.
arrays are primarily used to store rows with row and column characteristics ( form ) the data.
classification of 2php arrays
①, indexed arrays
The subscript of an array is an integer. Such an array is an indexed array
②, associative arrays
The subscript of an array is a string. Such an array is an associative array.
Creation of 3php arrays
①, indexed array creation
Example:
Description
the subscript of an array in PHP can be discontinuous.
Creation of ②, associative arrays
Grammar:
$arr = Array (key name = = Key value , key name = = Key value ,....);
$arr = [key name = = Key value , key name = = Key value ,....];
Description
the array elements in PHP consist of two parts, the key name (subscript ), the key value
Example:
4 Multi-dimensional arrays
a multidimensional array is supported in PHP, and if the element of an array is an array, then this is a multidimensional array.
5 array element Access
①, one-dimensional array element access
Grammar:
$ Array name [ subscript / key name ]
Example:
Access to ②, two-dimensional array elements
Grammar:
$ array name [ row subscript] [ column subscript ]
Example:
6 Length of the array
Count ()
Used to get the length of an array
Pointers to three arrays
array pointers are used to represent elements that are currently of interest.
Current ($arr) is used for the key value of the element to which the pointer is pointing
Key ($arr) is used for the name of the element that the current pointer points to
Next ($arr) moves the pointer down the array.
Prev ($arr) is used to move the pointer of an array up.
Reset ($arr); used to reset the pointer of an array ( homing , array pointers default to the first 1 elements ) .
End ($arr); used to move the pointer of an array to the last element.
Example:
Traversal of the four arrays 1for
The For loop is used to iterate through the data by using a loop control variable to simulate the subscript, only to traverse the next continuous or regular
but not The array subscript in PHP can be discontinuous and irregular, or it may be an associative array. For how associative arrays are traversed.
2foreach
①, grammar
foreach ($arr as "$key= ="$value ){
Loop Body
}
Description
$arr is the array to traverse ,$key,$value is a variable, and the variable name can be customized.
Example:
②,Foreah principle
First, the pointer to the array is reset.
reads the array element that the current pointer points to, and assigns the key name of the element to the variable $key, assigning the key value to the variable $value,
The pointer to the array is also moved down one line ( move the pointer down for the next loop ) .
foreach does not need us to control the number of loops, it automatically determines when to end the loop.
3while-each-list traversal
using the while loop, and the Each () function, thelist syntax structure is combined to iterate through the array.
①, each
Each ( array )
Description
Used to get the element key name and key value that the current pointer points to, and to represent both the index element and the relationship element, while moving the pointer down one line.
Example:
②,list
Grammar:
List ( variable ) = $arr
Description
Assigns an indexed element in an array $arr to a variable in the variable list.
Example:
③,while-each-list traversal array
③,foreach and list
Grammar:
List ( variable ) = $arr
Description
the right side of the list statement must be an array
Example:
Five array operations common functions 1 the length of the array
Count (array name)
2 getting the key names and key values for an array element
①, Array_keys ()
Get all the key names of an array element
②,array_values ()
Get all the key values of an array element
Example:
3 determine if key names and key values exist
①,array_k ey_exists (Key,arr)
used to determine if a key name exists in the array and returns true if it exists , otherwise false
②,in_array (value,arr);
used to determine if a key value exists in the array and returns true if it exists , otherwise false
Example:
4 Merging of arrays
Array_merge ( array 1, array 2...)
5 Sorting of arrays
①,sort ()
Sorting an array of key values in ascending order
②,rsort ()
descending sort of an array of key values
Example:
③,asort ();
array key values are sorted in ascending order, but the original subscript does not change
④,arsort ()
sorts the key values in descending order, but the original subscript does not change
6,extract
Used to decompress an array and convert the associated element to a variable with a key name.
Correlation algorithm of six arrays 1 sorting algorithm
①, Bubble Sort method
Principle:
②, insert Sort method
2. Search Algorithm
①, Sequential Lookup method
②, two-part search method
Premise:
Arrays must be ordered, and elements cannot be duplicated.
Learn to have-php basic grammar-06