The following code shows Examples of Typecasting of Variables in PHP.
<?php
echo '<h1>Example Demonstrating Type Casting of Variables in PHP</h1>';
$a=100;
$b=10.119;
$c=true;
$d='A String!';
echo 'a='.$a.' (Integer Variable)<br/>b='.$b.' (Float Variable)<br/>c='.$c.' (Boolean Variable)<br/>d='.$d.' (String Variable)';
$x1=(int)$b;
$x2=(float)$a;
$x3=(bool)$a;
$x4=(float)$c;
$x5=(unset)$d;
echo '<h2>After Typecasting...</h2>';
echo '<br/>'.$x1.' (Float Typecasted to Int)<br/>';
echo $x2.' (Int Typecasted to Float)<br/>';
echo $x3.' (Int Typecasted to Bool)<br/>';
echo $x4.' (Bool Typecasted to Float)<br/>';
echo '$x5='.$x5.'<br/>';
echo '(String Typecasted to null)<br/>';
?>
Output
Further Reading
Examples of Array Functions in PHP
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML