PHP $_POST Array Iteration?
Posted: Tue Jun 07, 2011 11:36 am
Hi guys,
I haven't been on these forums in a while, but I am back on now that school is out and everything! Okay, so basically I have some code that returns me an error when I checked it, but I don't know what I coded wrong. Here is the code for the erroneous function:
Then, I passed in a $_POST array to iterate through (this is after the user has submitted the form):
Please help!
I haven't been on these forums in a while, but I am back on now that school is out and everything! Okay, so basically I have some code that returns me an error when I checked it, but I don't know what I coded wrong. Here is the code for the erroneous function:
Code: Select all
$items = array();
$item_values = array();
$item_index = 0;
// Iterate through POST fields from form and add appropriate items
// to the $items[] array
function iterateArray($arr)
{
foreach ($arr as $key=>$value)
{
$arr[$key] = mysql_real_escape_string($value);
if ((int)$value > 0) {
$items[$item_index] = $key;
$item_values[$item_index] = $value;
$item_index++;
}
}
}
Code: Select all
iterateArray($_POST) or die('Failed to iterate $_POST fields');