[php]
$arr=array(
'one'=>array(
'name'=>'jiangtong',
'sex'=>'male'
),
'two'=>'zhaohaitao',
'three'= >'fanchangfa'
);
The above is the first element in the array that is two-dimensional, and the last two are one-dimensional. When we access one dimension, there are several ways: :
Copy code The code is as follows:
[php]
echo "$arr[two]"//key There is no single quotation mark
echo "$arr['two']"//If the key has single quotation marks, an error will occur. If we change it to echo "{$arr['two']}";, the result can be output correctly
echo "{$arr[two]}"//There are double braces, but the key does not have single quotes. In this case, PHP will first look for the constant banana, and if so, replace it with
, because there are no two constants, an error occurs
It can be seen that when accessing a one-dimensional array, either do not add keys or quotes (consider In the third case), if you add it, it will be enclosed by {}, you don’t need to add it at all.
Multidimensional array test
Copy code The code is as follows:
[php]
echo "$arr[one ][name]"; //The output result is Array[name]. It can be seen that it returns an array and only parses one dimension
echo"{$arr['one']['name']}";// The output result is jiangtong
Braces must be used when accessing multi-dimensional arrays. The key must be enclosed in double quotes
Array type
has been mentioned in the string type and is enclosed by braces If it is enclosed in key quotes, it is legal. Then PHP will first search to see if there is a constant named key. If there is a constant named key, it will be replaced. If not, a warning that the constant cannot be found will be generated before pressing the ordinary string. Processing, so it is recommended that you add single quotes
to convert it into an array and use (array) type or array (type). However, if you convert a value with only one value into an array, you will get an array of one element, and the subscript is 0. Converting NULL into an array will result in an empty array
We can change the value of the array when traversing the array. In PHP5.0 and above, we can use references
Copy code The code is as follows:
[php]
$arr=array('a','b','c','d','e' );
foreach($arr as &$value)
{
$value=strtoupper($value);
echo $value;
}//Output result ABCDE
Object object type
To instantiate an object, we use new to add a person class. We can use the following method
Copy code The code is as follows:
[php]
$objPerson=new person();
Forcing (object): If a If the object is converted to an object, then there will be no change. For any other value, an object of stdclass will be instantiated. If the value is NULL, an empty object will be instantiated. If the array is converted to an object, the key of the array will be used as Attributes of the object, value is the attribute value, and for other types of values, the member variable named scalar contains the value
Copy code The code is as follows:
[php]
$arr=array('one'=>'a','two'=>'b' );
$obj=(object)$arr;
echo $obj->one //The output result is a;
Note: This is an array of keys. If there is no character key array, I don’t know how to access it. Who knows and hopes to tell Brother, thank you.
For other values
Copy code The code is as follows:
[php]
$obj1=(object) 'jiang';
echo $obj1->scalar;//Output result jiang
NULL 空类型
null大小写不敏感,NULL类型只有一个取值,表示一个变量没有值,下面三种情况变量被认为为NULL
1.被赋值为NULL
2.尚未被赋值
3.被unset();
PHP type comparison tables
Comparisons of $x with PHP functions
Expression |
gettype() |
empty() |
is_null() |
isset() |
boolean :if($x)
|
$x = ""; |
string |
TRUE |
FALSE |
TRUE |
FALSE |
$x = null |
NULL |
TRUE |
TRUE |
FALSE |
FALSE |
var $x; |
NULL |
TRUE |
TRUE |
FALSE |
FALSE |
$x is undefined |
NULL |
TRUE |
TRUE |
FALSE |
FALSE |
$x = array(); |
array |
TRUE |
FALSE |
TRUE |
FALSE |
$x = false; |
boolean |
TRUE |
FALSE |
TRUE |
FALSE |
$x = true; |
boolean |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 1; |
integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 42; |
integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 0; |
integer |
TRUE |
FALSE |
TRUE |
FALSE |
$x = -1; |
integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "1"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "0"; |
string |
TRUE |
FALSE |
TRUE |
FALSE |
$x = "-1"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "php"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "true"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "false"; |
string |
FALSE |
FALSE |
TRUE |
TRUE |
Loose comparisons with ==
|
TRUE |
FALSE |
1 |
0 |
-1 |
"1" |
"0" |
"-1" |
NULL |
array() |
"php" |
"" |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
TRUE |
TRUE |
FALSE |
TRUE |
1 |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
0 |
FALSE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
TRUE |
FALSE |
TRUE |
TRUE |
-1 |
TRUE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
"1" |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
"0" |
FALSE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
"-1" |
TRUE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
NULL |
FALSE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
TRUE |
FALSE |
TRUE |
array() |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
TRUE |
FALSE |
FALSE |
"php" |
TRUE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
"" |
FALSE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
Strict comparisons with ===
|
TRUE |
FALSE |
1 |
0 |
-1 |
"1" |
"0" |
"-1" |
NULL |
array() |
"php" |
"" |
TRUE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
1 |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
0 |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
-1 |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
"1" |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
"0" |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
"-1" |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
FALSE |
NULL |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
FALSE |
array() |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
FALSE |
"php" |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
FALSE |
"" |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
FALSE |
TRUE |
http://www.bkjia.com/PHPjc/327569.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327569.htmlTechArticlePHP has a total of 8 data types: type name type represents value bool Boolean true, false integer integer -2147483647 -2147483648 string The length of the string string depends on the machine memory...