What are the potential pitfalls of mixing different data types (e.g., strings and numbers) in PHP calculations, and how can they be avoided?

Mixing different data types in PHP calculations can lead to unexpected results or errors. To avoid this issue, it's important to ensure that the data types being used in calculations are compatible. One way to do this is by explicitly converting data types as needed before performing calculations.

// Example of avoiding pitfalls when mixing data types in PHP calculations

// String containing a number
$numberString = "10";

// Convert the string to an integer before performing calculations
$number = (int)$numberString;

// Perform calculations with the converted integer
$result = $number + 5;

echo $result; // Output: 15