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;
}
}
?>
Funções para Manipulação de variáveis
Índice
- debug_zval_dump — Exibe a representação de um interno zend value
- doubleval — Sinônimo de floatval
- empty — Informa se a variável é vazia
- floatval — Retorna o valor float da variável
- get_defined_vars — Retorna o array com todas variáveis definidas
- get_resource_type — Retorna o tipo de resource
- gettype — Retorna o tipo da variável
- import_request_variables — Importa variáveis GET/POST/Cookie para o escopo global
- intval — Retorna o valor inteiro da variável
- is_array — Verifica se a variável é um array
- is_binary — Verifica se uma variável é uma nativa string binária
- is_bool — Verifica se a variável é um boleano
- is_buffer — Verifica se uma variável é uma nativa unicode ou string binária
- is_callable — Verifica se o conteúdo da variável pode ser chamado como função
- is_double — Sinônimo de is_float
- is_float — Informa se a variável é do tipo float
- is_int — Informa se a variável é do tipo inteiro
- is_integer — Sinônimo de is_int
- is_long — Sinônimo de is_int
- is_null — Informa se a variável é NULL
- is_numeric — Informa se a variável é um número ou uma string numérica
- is_object — Informa se a variável é um objeto
- is_real — Sinônimo de is_float
- is_resource — Informa se a variável é um resource
- is_scalar — Informa se é uma váriavel escalar
- is_string — Informa se a variável é do tipo string
- is_unicode — Verifica se uma variável é uma string unicode
- isset — Informa se a variável foi iniciada
- print_r — Prints human-readable information about a variable
- serialize — Generates a storable representation of a value
- settype — Atribui um tipo para a variável
- strval — Retorna o valor string de uma variável
- unserialize — Creates a PHP value from a stored representation
- unset — Destrói a variável especificada
- var_dump — Mostra informações sobre a variável
- var_export — Mostra ou retorna uma representação estruturada de uma variável
Funções para Manipulação de variáveis
jfrasca at sheerdev dot com
31-Aug-2005 02:27
31-Aug-2005 02:27
skelley at diff dot nl
22-Sep-2001 08:55
22-Sep-2001 08: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.
