 | | Offres d'emplois |  | Développeur web PHP/MYSQL en alternance Web Agency, partenaire d'ip-formation, offrant des possibilités d'évolutions, recherche dans le cadre d'un contrat de professionnalisation un dével... | |
 | | Avez vous lu ? |  | | |
|
 Forcer le type d'une variable | |  |

<?php
function format_values($val, $type) {
switch($type) {
case"int":
if(!is_int($val)) {
$val = intval($val);
}
break;
case"float":
if(!is_float($val)) {
$val = floatval($val);
}
break;
case"bool":
if(!is_bool($val)) {
$val = (bool)$val;
}
break;
case"array":
if(!is_array($val)) {
$val = (array)$val;
}
break;
case"string":
if(!is_string($val)) {
$val = (string)$val;
}
break;
}
return $val;
}
?>
|
|
|
 |
|