Last active
April 13, 2018 12:41
-
-
Save w-jerome/2e240938b9d24572cebfa14d6939f69f to your computer and use it in GitHub Desktop.
PHP — Convert Values Type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertValueType ( $value ) { | |
$valueConvert = intval($value); | |
if ($value === "0") { | |
$value = intval($value); | |
} else if ($value === true || $value === "true") { | |
$value = true; | |
} else if ($value === false || $value === "false") { | |
$value = false; | |
} else if ($value === null || $value === "null") { | |
$value = null; | |
} else if ($value === 0 || ($valueConvert != 0 || $valueConvert > 0)) { | |
$value = intval($value); | |
} else if ($valueConvert === 0 && mb_strlen($valueConvert) == mb_strlen($value)) { | |
$value = $value; | |
} else if ($valueConvert != 0 || $valueConvert > 0) { | |
$value = intval($value); | |
} else if ($valueConvert === 0 || $valueConvert == $value) { | |
$value = $value; | |
} else { | |
$value = $value; | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment