0

Actually i want to add both the values of ids 2 and the ids 3

<form method="post" name="fo" action="#">
    <input type="text" name="ids[]" value="2"/>
    <input type="text" name="amount[]" value="100"/>
    <input type="text" name="ids[]" value="3"/>
    <input type="text" name="amount[]" value="200"/>
    <input type="text" name="ids[]" value="2"/>
    <input type="text" name="amount[]" value="300"/>
    <input type="text" name="ids[]" value="3"/>
    <input type="text" name="amount[]" value="50"/>
    <input type="submit" name="submit"/>
</form>

<?php
$id=$_POST['ids'];
$am=$_POST['amount'];

$arr=array(
           array('id'=> $id,'am'=>$am)

           );

$heads = array();
$amounts = array();
$i = 0;
foreach($arr as $sub)
{
    $key = array_search($sub['id'], $heads);
    if($key)
    {
        $amounts[$key] += $sub['am'];
    }
    else
    {
        $heads["'" . $i . "'"] = $sub['id'];
        $amounts["'" . $i . "'"] = $sub['am'];
        $i++;
    }
}

print_r($heads);
print_r($amounts);
}

?>

Edited by Dilawar_1

3
Contributors
2
Replies
35
Views
1 Month
Discussion Span
Last Post by john_111
0

What are you trying to accomplish? When you say " Multidementional Array" from form, what are you doing with the array? The for post data is aready array.

0

Give your input fields names like id1, id2, id3 etc and amount 1, amount2, amount3, etc
THEN build your array by putting these values into their corresponding places in your array. You do this by having an action file for when the sumbit button is clicked.
Currently your form has no action, therefore no action will take place as the form input isn't being processed in any way. It's a dead form.

Edited by john_111

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.