PHP concatenation precedence

Viewed 1022

Is this behaviour correct in PHP?

<?php echo '-' . 1 + 1 . ' crazy cats'; ?>
// Outputs:
0 crazy cats

I understand that minus is being concatenated to the first '1' and '-1' casted to integer, and not '2' to string.

Please explain why.

What is the best way to solve it? This one?

<?php echo '-' . (string)1 + 1 . ' crazy cats'; ?>
5 Answers
Related