12 if ($allow_null && $var === null)
return null;
24 if (is_string($var) && ctype_digit($var)) $var = (int) $var;
27 if ((is_string($var) && is_numeric($var)) || is_int($var)) $var = (
float) $var;
30 if (is_int($var) && ($var === 0 || $var === 1)) {
32 } elseif (is_string($var)) {
33 if ($var ==
'on' || $var ==
'true' || $var ==
'1') {
35 } elseif ($var ==
'off' || $var ==
'false' || $var ==
'0') {
45 if (is_string($var)) {
49 if ($var ==
'')
return array();
50 if (strpos($var,
"\n") ===
false && strpos($var,
"\r") ===
false) {
53 $var = explode(
',',$var);
55 $var = preg_split(
'/(,|[\n\r]+)/', $var);
58 foreach ($var as $i => $j) $var[$i] = trim($j);
59 if ($type === self::HASH) {
62 foreach ($var as $keypair) {
63 $c = explode(
':', $keypair, 2);
64 if (!isset($c[1]))
continue;
65 $nvar[trim($c[0])] = trim($c[1]);
70 if (!is_array($var))
break;
71 $keys = array_keys($var);
72 if ($keys === array_keys($keys)) {
73 if ($type == self::ALIST)
return $var;
74 elseif ($type == self::LOOKUP) {
76 foreach ($var as $key) {
82 if ($type === self::ALIST) {
83 trigger_error(
"Array list did not have consecutive integer indexes", E_USER_WARNING);
84 return array_values($var);
86 if ($type === self::LOOKUP) {
87 foreach ($var as $key => $value) {
88 if ($value !==
true) {
89 trigger_error(
"Lookup array has non-true value at key '$key'; maybe your input array was not indexed numerically", E_USER_WARNING);