Avatar ·

How to convert a string to a number in PHP? All methods with examples

Hello everyone! I just started learning PHP and I have a problem. I'm writing a simple script that adds two numbers received from a form. But instead of addition, I'm getting string concatenation.\n\nHere's a simplified example:\n\n```php\n\n```\n\nActually, if I write `$sum = "10" + "20";` — it works and outputs 30. But when I try with real data from the form, the numbers don't add up, they just concatenate: "1020". I read that PHP converts types automatically, but why does concatenation happen? I tried casting `(int)` before the variables, but it didn't help.\n\nI need a reliable solution that will