My code is:
HTML part for POST:
<form action='key.php' method='POST'>
<input type='number' name='consumervar[]' value='512'/>
<input type='number' name='consumervar[]' value='256'/>
<input type='number' name='consumervar[]' value='1024'/>
<input type='submit'/>
</form>
PHP Code for key.php:
<?PHP
foreach ($_POST as $key => $value) {
$consumervar = $value*64;
}
print_r($consumervar); // this is for for debug (see array contents)
?>
BUt when i run everything it reproduces:
Fatal error: Unsupported operand types in /var/blahblah/blahblah/key.php on line 3
Please help. How to do it correctly? It need to multiply every posted value with integer 64.
the loop should be
as written, your code pulls out the ARRAY of consumervar values, which you try to multiply. You cannot “multiply” arrays in php.
As well, note that the $key/$value produced by the loop are simply copies of what exists in the array. You are not changing the array’s values. For that, you should be doing