I have several radiobutton arrays.
They’re named awardLevel0[] , awardLevel1[] , awardLevel2[], and so on, generated dynamically by the user.
I want to know if this function will work to get their total sum values.
[php]function awardCheck () {
$exist = true;
$num = 0;
$endsum = 0;
while ($exist)
{
$names = “awardLevel” . $num;
$awardLev = $_POST[$names];
if (empty($awardLev)){
$exist = false;
return $endsum;;
}
else
$endsum = $endsum + $awardLev;
$num++;
}
return $endsum;
}[/php]
if you just want to add the values have a look at array_sum http://php.net/manual/en/function.array-sum.php
I could use that, but I still need to $_POST each array, but since the buttons are dynamically generated I have to do a for loop and check how many buttons exist and get the data from only the ones that exist…
Is there a way to post for a name through a string?
like instead of
[php]$namething = $_POST[‘something’];[/php]
could i
[php]$nameofthing = “something”;
$namething = $_POST[$nameofthing];
[/php]
??
I guess you could do that, you could also use a foreach loop on $_POST