I have a foreach loop for an array
foreach ($somethings as $key2 => $something)
{
$value = 0;
if ($something['ElementID'] == $value)
{
unset($available);
}
$total += $something['Cost'];
$singleprice = $available['Cost'];
}
I need to be able to return $total and $singleprice - Total adding up all the values within the key, $singleprice returning only 1 instead of all added up
The only way I've managed to return this value is by creating another foreach loop within this foreach loop like so:
foreach ($somethings as $key2 => $something)
{
$value = 0;
if ($something['ElementID'] == $value)
{
unset($available);
}
foreach($somethings as $key3 => $singlesomething)
{
$singleprice = $singlesomething['Cost'];
}
$total += $something['Cost'];
}
Why will the above first method return nothing? I then use this variable which now has the data in a Div Data- (data-single-cost="'.$singleprice.'" ) which is then used to POST a form
$singleprice = $_POST['single-cost'];
Yet it returns 0 even with the second method successfully getting the value
any ideas what I'm doing wrong?