note 52320 deleted from function.is-numeric by cmb

From: Date: Sun, 23 Jun 2019 10:32:39 +0000
Subject: note 52320 deleted from function.is-numeric by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211347@lists.php.net to get a copy of this message
Note Submitter: Titouthat ---- This function converts an input string into bool, int or float depending on its content. <?php function convert_type( $var ) { if( is_numeric( $var ) ) { if( (float)$var != (int)$var ) { return (float)$var; } else { return (int)$var; } } if( $var == "true" ) return true; if( $var == "false" ) return false; return $var; } ?> '90' return an int '90.9' return a float 'true' return a bool '90.0' return a int

« previous php.notes (#211347) next »