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

H

How Can We Help?

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

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:

{codecitation style=”brush: PHP;”}
$post_int = array_map(‘intval’, $_POST); //Converting every post value to integer
$get_int = array_map(‘intval’, $_GET); //Converting every get value to integer
{/codecitation}

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me