What is the difference between adding two variables as strings versus adding them as floats in PHP?

When adding two variables as strings in PHP, the values are concatenated together as a single string. However, when adding two variables as floats in PHP, the values are added numerically. It's important to ensure that the variables are of the correct type when performing arithmetic operations to get the desired result.

// Adding two variables as strings
$var1 = "10";
$var2 = "20";
$resultString = $var1 . $var2; // Result: "1020"

// Adding two variables as floats
$var3 = 10.5;
$var4 = 20.75;
$resultFloat = $var3 + $var4; // Result: 31.25