tags:

views:

77

answers:

2

I have a web form and when it gets submitted I post the data to a PHP page. Now I need PHP to convert every value from the POST to be converted to an integer. At the moment I tried do do it as below

$_POST = array_map("convert",$_POST);

function convert(val){
    return (int)$val;
}

Is there a built-in PHP function for this.

+3  A: 

What about using intval, instead of your own convert function ?

Returns the integer value of var , using the specified base for the conversion (the default is base 10).

(And, of course, still using array_map)

Pascal MARTIN
+8  A: 

I thought that:

$res = array_map('intval', $_POST);

is short enough.

SilentGhost