xxxxxxxxxx
phpCopy$variableName = (int)$stringName
$variableName = (float)$stringName
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