1phpCopy<?php
2$variable = "abc";
3$integer = (int)$variable;
4echo "The variable has converted to a number and its value is $integer.";
5?>
6
1phpCopy<?php
2$variable = "53";
3$integer = intval($variable);
4echo "The variable $variable has converted to a number and its value is $integer.";
5echo "\n";
6
7$variable = "25.3";
8$float = floatval($variable);
9echo "The variable $variable has converted to a number and its value is $float.";
10?>
11
1phpCopy<?php
2$variable = "2020Time";
3$integer = intval($variable);
4echo "The variable $variable has converted to a number and its value is $integer.";
5echo "\n";
6
7$variable = "Time2020";
8$integer = intval($variable);
9echo "The variable $variable has converted to a number and its value is $integer.";
10echo "\n";
11
12$variable = "25.3Time";
13$float = floatval($variable);
14echo "The variable $variable has converted to a number and its value is $float.";
15echo "\n";
16
17$variable = "Time25.3";
18$float = floatval($variable);
19echo "The variable $variable has converted to a number and its value is $float.";
20?>
21
1phpCopy<?php
2$variable = "45";
3settype($variable, "integer");
4echo "The variable has converted to a number and its value is $variable.";
5?>
6
1phpCopy<?php
2$variable = "10";
3$integer = (int)$variable;
4echo "The variable $variable has converted to a number and its value is $integer.";
5echo "\n";
6
7$variable = "8.1";
8$float = (float)$variable;
9echo "The variable $variable has converted to a number and its value is $float.";
10?>
11
1phpCopy$variableName = (int)$stringName
2$variableName = (float)$stringName
3