method correctTypes documentation in bbn\Str
If it looks like an int or float type, the string variable is converted into the correct type.
Example
X::dump(\bbn\Str::correctTypes(1230));
// (int) 1230
X::dump(\bbn\Str::correctTypes(12.30));
// (float) 12.3
X::dump(\bbn\Str::correctTypes("12.3"));
// (float) 12.3
X::dump(\bbn\Str::correctTypes([1230]));
// (int) [1230]
function($st)
{
if (\is_string($st)) {
if (self::isBuid($st)) {
$st = bin2hex($st);
}
else{
if (self::isJson($st)) {
if (strpos($st, '": ') && ($json = json_decode($st))) {
return json_encode($json);
}
return $st;
}
$st = trim(trim($st, " "), "\t");
if (self::isInteger($st)
&& ((substr((string)$st, 0, 1) !== '0') || ($st === '0'))
) {
$tmp = (int)$st;
if (($tmp < PHP_INT_MAX) && ($tmp > -PHP_INT_MAX)) {
return $tmp;
}
}
// If it is a decimal, not starting or ending with a zero
elseif (self::isDecimal($st)) {
return (float)$st;
}
return normalizer_normalize($st);
}
}
elseif (\is_array($st)) {
foreach ($st as $k => $v) {
$st[$k] = self::correctTypes($v);
}
}
elseif (\is_object($st)) {
$vs = get_object_vars($st);
foreach ($vs as $k => $v) {
$st->$k = self::correctTypes($v);
}
}
return $st;
}
If it looks like an int or float type, the string variable is converted into the correct type. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions