 | | Offres d'emplois |  | Lead developer PHP On recherche un développeur-intégrateur adepte des bonnes pratiques du Web.
Mission :
- Participer à la conception technique des projets web
... | |
 | | 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;
}
?>
|
|
|
 |
|