Home PHP How to convert all $_POST or $_GET values to Integers?
 
 
 

How to convert all $_POST or $_GET values to Integers?

PDF Print E-mail

Question: How to convert all $_POST or $_GET values to Integers?

 

Answer:

By using the built-in PHP functions  array_map and intval.

  • array_map = Applies the callback to the elements of the given arrays, this applies the function for each value of an array (PHP 4 >= 4.0.6, PHP 5)
  • intval = Get the integer value of a variable (PHP 4, PHP 5)

Examples:

$post_int = array_map('intval', $_POST); //Converting every post value to integer
$get_int = array_map('intval', $_GET); //Converting every get value to integer

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!