PHP Numbers
You must have noticed one thing that whenever we take the numbers in the identification, then its conversion becomes automatic Or we can say that whatever number we give through Varible, the data type of the number is automatically correct according to its data type.Then, if you assign a string to the same variable, the type will change to a string. PHP numbers with integers
This automatic conversion can sometimes break your code.
PHP Casting Strings and Floats to Integers
Sometimes you need to cast a numerical value into another data type.
The (int), (integer), or intval() function are often used to convert a value to an integer.
Example
Cast float and string to integer:
Example
// Cast string to int
$xx = "232.268";
$int_cast = (int)$xx;
echo $int_cast;
NOTE :- Video on This Topic :- Soon
Have a Nice Stay Here : - )
<!DOCTYPE html>
<html>
<head>
<title>PHP casting strings and floats to integers </title>
</head>
<body>
<h1> </h1>
<?php
// cast float to int
<html>
<head>
<title>PHP casting strings and floats to integers </title>
</head>
<body>
<h1> </h1>
<?php
// cast float to int
$x = 437.2453;
$int_cast = (int)$x;
$int_cast = (int)$x;
echo $int_cast;
echo "<br>";
$xx = "232.268";
$int_cast = (int)$xx;
echo $int_cast;
?>
437
232
NOTE :- Video on This Topic :- Soon
Have a Nice Stay Here : - )
0 comments:
Post a Comment
For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.