I need to summarize the data [$_SESSION['sIncome'] based on the detail data entered in $POST['mycensus'] from my HTML form. Some sample data is:
There should be three element in sIncome - state, income, count. I just cannot get the syntax correct in my function. I am still very confused on how the php arrays work. They are very different from what I am used to in other languages.
$POST['mycensus'] is updated from the HTML form
mycensus[0][SurveyDate] = "06/29/1956"
mycensus[0][Income] = 1000
mycensus[0][CountyState] = "Hamilton|Oh"
<input type="date" id="txtDateOfSurvey" name="mycensus[0][SurveyDate]"
<input type="numeric" id="txtIncome" name="mycensus[0][Income]"
<select id="optCountyState" name="mycensus[0][CountyState]"
<option value="Hamilton|Oh">Hamilton, Oh</option>
<option value="Boone|Ky">Boone, Ky</option>
function update_array_value3( &$array )
{
foreach ($array as &$row)
{
$arrCountyState = explode( "|", $row['CountyState'] );
$key = $arrCountyState[1];
if( !isset( $_SESSION['sIncome'][$key] ) )
{
$_SESSION['sIncome'][$key] = $row['Income'];
$_SESSION['sIncome']['count'] = 1;
} else
{
$_SESSION['sIncome']['state'] = $key;
$_SESSION['sIncome']['income'] += $row['Income'];
$_SESSION['sIncome']['count'] += 1;
}
}
}
update_array_value3( $_POST['mycensus'] );