2014-09-16 2 views
0

PHP의 정수와 문자열 변수에 대한 규칙이 약간 불분명합니다.int와 str 변수

카운터 (1부터 시작해서 위쪽으로 계산되는 간단한 정수)를 다루는 경우 정수를 변수로 지정한 다음 사용시 문자열로 변환해야하거나 문자열로 남겨두고 변환이 자동으로 수행 될 수 있습니까 PHP는 런타임에?

다른 규칙이있는 사례가 너무 많습니까? 몇 가지 생각은 감사하겠습니다 ...

+0

PHP를보십시오. 숫자 형을 사용하고 (예 :'echo'를 사용하여) 출력 할 때 자동으로 문자열로 변환됩니다. – knittl

+0

http://php.net/manual/en/language.types.type-juggling.php 알고 싶은 내용은 여기 – gvgvgvijayan

+0

예. PHP는 비밀리에 또는 정수 또는 문자열을 자동으로 이해합니다. –

답변

0

PHP은 필요할 때 자동으로 valriables을 변환합니다. 당신이 그들을 비교하려고 할 때 조심해야합니다.

If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.

자동으로 문자열과 숫자 유형 사이의 변환합니다 this

0

PHP에서 변수 선언은 당신이 그것에 할당 된 데이터에 적절한 형식을 취할 것입니다.

$var = 1; //here $var is an int 
$var = '1'; // now is a string 
$var = true; //and now a boolean