I needed a simple function that would reduce any kind of variable to a string or number while retaining some semblance of the data that was stored in the variable. This is what I came up with:
<?
function ReduceVar ($Value) {
switch (gettype($Value)) {
case "boolean":
case "integer":
case "double":
case "string":
case "NULL":
return $Value;
case "resource":
return get_resource_type($Value);
case "object":
return ReduceVar(get_object_vars($Value));
case "array":
if (count($Value) <= 0)
return NULL;
else
return ReduceVar(reset($Value));
default:
return NULL;
}
}
?>
Variable handling 함수 목록
Table of Contents
- debug_zval_dump — Dumps a string representation of an internal zend value to output
- doubleval — 별칭: floatval
- empty — 변수가 비어있는지 검사합니다
- floatval — 변수의 float 값을 얻습니다
- get_defined_vars — 모든 정의된 변수의 배열을 반환
- get_resource_type — 자원형을 반환
- gettype — 변수의 자료형을 얻습니다
- import_request_variables — GET/POST/쿠키 변수를 전역으로 가져옵니다
- intval — 변수의 정수값을 얻습니다
- is_array — 변수가 배열인지 확인
- is_binary — Finds whether a variable is a native binary string
- is_bool — 변수가 논리형인지 확인
- is_buffer — Finds whether a variable is a native unicode or binary string
- is_callable — 변수 내용을 함수처럼 호출할 수 있는지 확인
- is_double — 별칭: is_float
- is_float — 변수의 자료형이 소수인지 확인합니다
- is_int — 변수의 자료형이 정수인지 확인합니다
- is_integer — 별칭: is_int
- is_long — 별칭: is_int
- is_null — 변수가 NULL인지 확인합니다
- is_numeric — 변수가 수나 수 문자열인지 확인합니다
- is_object — 변수가 객체인지 확인합니다
- is_real — 별칭: is_float
- is_resource — 변수가 자원인지 확인
- is_scalar — 변수가 스칼라인지 확인
- is_string — 변수의 자료형이 문자열인지 확인합니다
- is_unicode — Finds whether a variable is a unicode string
- isset — 설정된 변수인지 확인
- print_r — 변수에 관한 정보를 사람이 읽기 편하게 출력
- serialize — 값의 저장 표현을 생성
- settype — 변수의 자료형을 설정
- strval — 변수의 문자열 값을 얻습니다
- unserialize — 저장 표현에서 PHP 값을 작성
- unset — 주어진 변수를 제거
- var_dump — 변수에 대한 정보를 덤프
- var_export — 변수를 처리가능한 문자열 표현으로 출력하거나 반환합니다
Variable handling 함수 목록
jfrasca at sheerdev dot com
31-Aug-2005 05:27
31-Aug-2005 05:27
skelley at diff dot nl
22-Sep-2001 11:55
22-Sep-2001 11:55
Sorry to say Mykolas, but your definition would not be correct.
isempty() evaluates to true for NULL, 0, "", false or 'not set' for any variable, object etc. that can be set to a value.
isset() evaluates to true if the variable, object etc. exists at all, whether it is 'empty' or not.
Example:
$foo = 0;
isset($foo); //will evaluate to true.
!empty($foo); //will evaluate to false.
unset($foo);
isset($foo); //will evaluate to false.
!empty($foo); //will evaluate to false.
