Skip to main content
added 165 characters in body
Source Link
user2039981
user2039981

May I write:

"1" + 1; 

In PHP, to get 2, or do I have to cast first:

(int)"1" + 1; 

? The reason I wonder this is because I have a counter in a text file that I want to increment:

file_put_contents($filename, file_get_contents($filename) + 1); 

May I write:

"1" + 1; 

In PHP, to get 2, or do I have to cast first:

(int)"1" + 1; 

?

May I write:

"1" + 1; 

In PHP, to get 2, or do I have to cast first:

(int)"1" + 1; 

? The reason I wonder this is because I have a counter in a text file that I want to increment:

file_put_contents($filename, file_get_contents($filename) + 1); 
Source Link
user2039981
user2039981

Is "1" + 1 correct in PHP?

May I write:

"1" + 1; 

In PHP, to get 2, or do I have to cast first:

(int)"1" + 1; 

?