Recent Articles
- Watermark Images with Other Images and Text on the Fly, Started by shabbir in PHP
- Securing basic PHP flaws for newbies [Part 1], Started by Deadly Ghos7 in PHP
- PHP Code Optimization: Do's and Don'ts, Started by hurricanesoftwares in PHP
- Password Creator: using bitwise operations, Started by extraweb in PHP
- Google Image Leecher - Php Code, Started by o0darkEvil0o in PHP
Similar Articles
- PHP On-The-Fly!, Started by Kings in PHP
- Track your visitors, using PHP, Started by Kings in PHP
- Optimize file uploads in PHP, Started by pradeep in PHP
- PHP and Cookies; a good mix!, Started by Kings in PHP
Code: PHP
<?php
$mystring = "wombat";
$myinteger = (integer)$mystring
?>
At first, $mystring contains a string. However, we type cast it to be an integer, so PHP will convert it to an integer, and place the result into $myinteger. You can type cast as boolean using (bool), string using (string), and floating-point using (float).
Type casting is most often used to specifically enforce a type in order to provide extra security or just to make sure a set type of data is being used. For example, if your script absolutely requires an integer number, it's a smart move to typecast your variable with (integer) so that PHP will convert any other type to integer or do nothing if the type is already integer. Converting a float to an integer will automatically round the number down, and is actually faster than using the equivalent function.











Yet to provide details about himself



Linear Mode

