In reply to Philip, form data could also be an array. so there are two types you can expect from $_REQUEST (and it's associates): string and array.
변수형
Table of Contents
소개
PHP는 8가지의 기본 변수형을 지원한다.
4가지 스칼라형:
2가지 복합 타입: 그리고 최종적으로 다음의 2가지 타입: 이 매뉴얼에서는 몇가지의 의사(pseudo) 타입도 소개한다. for readability reasons: "double" 타입과 비슷한 타입을 볼수 있을것이다. double은 float과 같은 타입이다. 두개의 타입이 존재하는 이유는 역사적인 이유일뿐이다.보통은 프로그래머가 변수의 타입을 결정할수 없다. 대신에, PHP가 변수가 사용되는 환경에 따라 실시간으로 결정하게 된다.
Note: 표현식의 타입과 값을 확인하려한다면, var_dump()을 사용한다. 디버깅을 위해 타입을 판독하려고 하면, gettype()를 사용한다. 정확히 어떠 타입을 사용하는지 확인하려면 gettype()함수를 사용하지 말고, is_type함수를 사용하도록 한다. 몇가지 예제 코드를 보자:
<?php
$bool = TRUE; // a boolean
$str = "foo"; // a string
$int = 12; // an integer
echo gettype($bool); // prints out "boolean"
echo gettype($str); // prints out "string"
// If this is an integer, increment it by four
if (is_int($int)) {
$int += 4;
}
// If $bool is a string, print it out
// (does not print out anything)
if (is_string($bool)) {
echo "String: $bool";
}
?>
변수를 다른 타입으로 변경하려한다면 변수를 캐스트하거나 settype()함수를 사용하면 된다.
변수는 특수한 상황에서는 그 당시에 무슨 타입을 쓰는지에 따라 다른 값으로 변경될수 있다는 것에 주의 해야 한다. 자세한 정보는 타입 저글링을 참고. 타입 비교 테이블를 보면, 다양한 타입의 비교의 예제코드를 볼수 있다.
변수형
jonah_whalehosting_ca
12-Apr-2007 10:33
12-Apr-2007 10:33
arjini at gmail dot com
06-Dec-2005 12:32
06-Dec-2005 12:32
Note that you can chain type castng:
var_dump((string)(int)false); //string(1) "0"
shahnaz khan
18-Mar-2005 04:40
18-Mar-2005 04:40
if we use gettype() before initializinf any variable it give NULL
for eg.
<?php
$foo;
echo gettype($foo);
?>
it will show
NULL
Trizor of www.freedom-uplink.org
29-Jun-2004 06:14
29-Jun-2004 06:14
The differance of float and double dates back to a FORTRAN standard. In FORTRAN Variables aren't as loosly written as in PHP and you had to define variable types(OH NOES!). FLOAT or REAL*4 (For all you VAX people out there) defined the variable as a standard precision floating point, with 4 bytes of memory allocated to it. DOUBLE PRECISION or REAL*8 (Again for the VAX) was identical to FLOAT or REAL*4, but with an 8 byte allocation of memory instead of a 4 byte allocation.
In fact most modern variable types date back to FORTRAN, except a string was called a CHARACHTER*N and you had to specify the length, or CHARACHTER*(*) for a variable length string. Boolean was LOGICAL, and there weren't yet objects, and there was support for complex numbers(a+bi).
Of course, most people reading this are web programmers and could care less about the mathematical background of programming.
NOTE: Object support was added to FORTRAN in the FORTRAN90 spec, and expanded with the FORTRAN94 spec, but by then C was the powerful force on the block, and most people who still use FORTRAN use the FORTRAN77.
