xxxxxxxxxx
// Type casting in PHP
// Explicit type casting
$number = (int) "42"; // Casts string to integer
$float = (float) "3.14"; // Casts string to float
$bool = (bool) "true"; // Casts string to boolean
// Implicit type casting
$sum = "10" + 5; // Implicitly casts "10" to integer and performs addition
$result = 12.5 * "2"; // Implicitly casts "2" to float and performs multiplication
// Checking type
$value = "42";
if (is_string($value)) {
echo "Value is a string.";
} elseif (is_int($value)) {
echo "Value is an integer.";
} elseif (is_float($value)) {
echo "Value is a float.";
} elseif (is_bool($value)) {
echo "Value is a boolean.";
} elseif (is_array($value)) {
echo "Value is an array.";
} else {
echo "Value has an unknown type.";
}