phpCopy<?php$variable="53";$integer=intval($variable);echo"The variable $variable has converted to a number and its value is $integer.";echo"
";$variable="25.3";$float=floatval($variable);echo"The variable $variable has converted to a number and its value is $float.";?>
method_1:intval($string);//for string to integerfloatval($string);//for string to float
method_2:$int=(int)$string;//string to int$float=(float)$string;//string to float
phpCopy<?php$variable="10";$integer=(int)$variable;echo"The variable $variable has converted to a number and its value is $integer.";echo"
";$variable="8.1";$float=(float)$variable;echo"The variable $variable has converted to a number and its value is $float.";?>
Using intval()andfloatval()Function. The intval()andfloatval() functions can also be used to convert the string into its corresponding integer andfloat values respectively.echofloatval($num);