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

No Comments

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}

Image Credits: Photo by Isis França on Unsplash.

Last Updated On March 22, 2018

Related Articles

No results found

Leave a Reply

avatar
  Subscribe  
Notify of
Menu
Copy link