Chinese characters can be placed in the php array. Because PHP is a programming language with weak data types, arrays in PHP can store any number of data of any type, that is, there is no limit on the type of array elements, which can be numbers, Boolean values, arrays, strings, etc.; while strings It can be divided into pure English strings, pure Chinese strings and mixed Chinese and English strings.
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
Array is one of the most important data types in PHP First, it is widely used in PHP. Because PHP is a programming language with weak data types, array variables in PHP can store any number of data of any type, and can implement the functions of data structures such as heaps, stacks, and queues in other strong data types.
Simply put,There is no restriction on the type of PHP array elements, which can be numbers, strings, Boolean values, arrays, Object objects, etc.
A string is a continuous sequence of characters, consisting of a series of characters, where each character is equivalent to one byte.
Strings can be divided into pure English strings, pure Chinese strings and mixed Chinese and English strings. Therefore, Chinese characters can be placed in the php array.
Example 1: Put pure English strings in php array
Example 2: php array Put the pure Chinese string
. It should be noted that in PHP, one Chinese character occupies three characters, so the length of the two Chinese strings in the above example For 6.
Example 3: Put Chinese and English mixed strings in the php array
Extended knowledge: Chinese Two processing functions for strings
1. Chinese interception: mb_substr()
mb_substr( $str, $start, $length, $encoding )
$str, the string that needs to be truncated
$start, the starting point of truncation, the starting point is 0
mb_strlen( $str, $encoding )
PHP Video Tutorial"
The above is the detailed content of Can't Chinese characters be placed in the php array?. For more information, please follow other related articles on the PHP Chinese website!