xxxxxxxxxx
$string = "42"; // Replace "42" with the actual string you want to convert
$integer = (int) $string;
echo $integer; // Output: 42 (as integer)
// If the string is not a valid representation of an integer, it will be converted to 0.
xxxxxxxxxx
phpCopy<?php
$variable = "53";
$integer = intval($variable);
echo "The variable $variable has converted to a number and its value is $integer.";
echo "\n";
$variable = "25.3";
$float = floatval($variable);
echo "The variable $variable has converted to a number and its value is $float.";
?>
xxxxxxxxxx
method_1:
intval($string);//for string to integer
floatval($string); //for string to float
method_2:
$int = (int)$string;//string to int
$float = (float)$string;//string to float
xxxxxxxxxx
$num = "3.14";
$int = (int)$num;//string to int
$float = (float)$num;//string to float