1, Intval & (int) can not be converted to Object.
2, conversion efficiency (int) > Intval () > sprintf (Intval is the built-in method of PHP, relatively low efficiency).
3, the other exactly the same.
4, input 0123, the 0x123 (int) function will also be in the octal and 16 binary conversion.
Test code:
$n = "19.99";
$example = Array (',
', 19.99, ' 19.99 ', ', ' abc123 ', ' 123abc ', 0x20, ' 0x20 ', Array (' 19.99 '), ' +41 ', ' -41 ',
' 10 000000000000000000000000000000 ', (float) 1999, NULL, $n *100, Strval ($n *100), ' j18ugj9hu0gj5hg ', 0123
);
foreach ($example as $key => $value) {
echo ' Transform value is: '. GetType ($value). ' . Json_encode ($value). "<br>";
echo "Intval is:", Intval ($value). " <br> ";
echo "(int) is:", (int) ($value). " <br> ";
echo "--------------------------------". "<br>";
}
Run Result:
The Transform Value Is:integer 19
Intval is:19
(int) is:19
--------------------------------
The Transform Value is:string "19"
Intval is:19
(int) is:19
--------------------------------
The Transform Value is:double 19.99
Intval is:19
(int) is:19
--------------------------------
The Transform Value is:string "19.99"
Intval is:19
(int) is:19
--------------------------------
The Transform Value is:string ""
Intval is:0
(int) is:0
--------------------------------
The Transform Value is:string "abc123"
Intval is:0
(int) is:0
--------------------------------
The Transform Value is:string "123ABC"
Intval is:123
(int) is:123
--------------------------------
The Transform Value Is:integer 32
Intval is:32
(int) is:32
--------------------------------
The Transform Value is:string "0x20"
Intval is:0
(int) is:0
--------------------------------
The Transform Value is:array ["19.99"]
Intval is:1
(int) is:1
--------------------------------
The Transform Value is:string "+41"
Intval is:41
(int) is:41
--------------------------------
The Transform Value is:string "-41"
Intval is:-41
(int) is:-41
--------------------------------
The Transform Value is:string "10000000000000000000000000000000"
Intval is:2147483647
(int) is:2147483647
--------------------------------
The Transform Value is:double 1999
Intval is:1999
(int) is:1999
--------------------------------
The Transform Value is:null NULL
Intval is:0
(int) is:0
--------------------------------
The Transform Value is:double 1999
Intval is:1998
(int) is:1998
--------------------------------
The Transform Value is:string "1999"
Intval is:1999
(int) is:1999
--------------------------------
The Transform Value is:string "J18UGJ9HU0GJ5HG"
Intval is:0
(int) is:0
--------------------------------
The Transform Value Is:integer 83
Intval is:83
(int) is:83
--------------------------------