This is a very basic problem, but I still do not understand.
(array)$arr
, is this a quick definition of arr as an array? But if you write like this,
(array)$arr;var_dump($arr);
PHP will still error AH and print it is not an empty array, similar to (int) $i, what is the use of it? Don't laughed at ....
Reply content:
This is a very basic problem, but I still do not understand. (array)$arr
, is this a quick definition of arr as an array? However, if you write this (array)$arr;var_dump($arr);
PHP will be error AH and print it is not an empty array, similar to (int) $i, what is the use? Don't laughed at ....
Landlord himself execute the following code will know
$a = 1;$b = (array)$a;var_dump($b);
$a = 'test';$b = (array)$a;var_dump($b);
$a = new stdClass();$a->key = 'value';$b = (array)$a;var_dump($b);
Type conversions, very basic issues.
Novice suggested document Look three times, book read three times
is a type of forced conversion method for PHP.
(int), (integer)-Converted to integral type
(bool), (Boolean)-converted to Boolean
(float), (double), (real)-converts to floating-point type
(string)-converts to a string
(array)-Convert an array
(object)-Convert to Object
(array)$arr;var_dump($arr);
The error is because you did not initialize the variable, this is very strange, haha, do not care too much.
can also use
settype( mixed var, string type );intval(mixed var);
This kind of conversion, the manual may not. But Baidu Google a lot. Recommended for beginners first search. Might be more likely to learn