mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Add description of typecasting
This commit is contained in:
parent
34852cc8be
commit
c3cc11f2a8
@ -144,7 +144,11 @@ echo $string + $string; // Also outputs 2 because the + operator converts the st
|
|||||||
|
|
||||||
$string = 'one';
|
$string = 'one';
|
||||||
echo $string + $string; // Outputs 0 because the + operator cannot cast the string 'one' to a number
|
echo $string + $string; // Outputs 0 because the + operator cannot cast the string 'one' to a number
|
||||||
|
```
|
||||||
|
|
||||||
|
Type casting can be used to treat a variable as another type temporarily by using cast operators in parentheses.
|
||||||
|
|
||||||
|
```php
|
||||||
$boolean = (boolean) $integer; // $boolean is true
|
$boolean = (boolean) $integer; // $boolean is true
|
||||||
|
|
||||||
$zero = 0;
|
$zero = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user