PHP How to send email to 2D array

Below is the Data(array that I’m trying to loop through)..

mind you the [DIJF0BWTS5DVLL9N5] is converted to a email address.
I tried using Nested Foreach loop it still sends all products to each [DIJF0BWTS5DVLL9N5](retailers email)

Array
(
    [DIJF0BWTS5DVLL9N5] => Array
        (
            [0] => Array
                (
                    [name] => Cowbell Chocolate
                    [price] => 750
                    [image] => Cowbell_milk.png
                    [productid] => 303
                    [retailerid] => DIJF0BWTS5DVLL9N5
                    [quantity] => 1
                    [code] => JH8YZL
                )

            [1] => Array
                (
                    [name] => Grandmas Cookies
                    [price] => 160
                    [image] => 0.036373001403792407.jpg
                    [productid] => 203
                    [retailerid] => DIJF0BWTS5DVLL9N5
                    [quantity] => 1
                    [code] => JH8YZL
                )

            [2] => Array
                (
                    [name] => Nido Milk
                    [price] => 800
                    [image] => 1498239307_nido.jpg
                    [productid] => 302
                    [retailerid] => DIJF0BWTS5DVLL9N5
                    [quantity] => 1
                    [code] => JH8YZL
                )

        )

    [DG8FSXW65OHCWJU0S] => Array
        (
            [0] => Array
                (
                    [name] => Barbaras Oat Crunch
                    [price] => 680
                    [image] => 0.917743001403788143.jpg
                    [productid] => 199
                    [retailerid] => DG8FSXW65OHCWJU0S
                    [quantity] => 1
                    [code] => JH8YZL
                )

        )

    [DIIGL2G07Y9E16NUO] => Array
        (
            [0] => Array
                (
                    [name] => Mini-Wheats
                    [price] => 700
                    [image] => 0.104168001409581063.jpg
                    [productid] => 237
                    [retailerid] => DIIGL2G07Y9E16NUO
                    [quantity] => 1
                    [code] => JH8YZL
                )

            [1] => Array
                (
                    [name] => Gullon Digestive Mueshli
                    [price] => 420
                    [image] => 0.064033001466093176.jpg
                    [productid] => 267
                    [retailerid] => DIIGL2G07Y9E16NUO
                    [quantity] => 1
                    [code] => JH8YZL
                )

        )

    [DKIK83VSGBJ8G1Q3O] => Array
        (
            [0] => Array
                (
                    [name] => chapagetti
                    [price] => 900
                    [image] => chapagetti.jpg
                    [productid] => 307
                    [retailerid] => DKIK83VSGBJ8G1Q3O
                    [quantity] => 1
                    [code] => JH8YZL
                )

        )

)


Source: stackoverflow-php

Closing Tags After Last Row

In a function, there is a foreach loop that is calling up another function to pull out secondary notes and sublists to append to the main data. It all works except for one part where there is a sublist, I cannot seem to make it close the tags. This is what I have but perhaps there is some other way?

global $rowCount;

$rowCount++;
$Count = array($rowCount);

foreach ($Count as $key => $a) :
   if (end($Count) == $a) :
       // Close the subtable after last row
       $NotesText .= "</div>nn";
       // Restart row table
       $NotesText .= "<div id="css-table">n";
   endif;
endforeach;

Using print_r($Count) the array looks something like this and I’m not an expert at arrays but it appears that it is creating individual arrays, one for each line:

Array ( [0] => 1 )
Array ( [0] => 2 )
Array ( [0] => 3 )
Array ( [0] => 4 )
Array ( [0] => 5 )
Array ( [0] => 6 )
Array ( [0] => 7 )
Array ( [0] => 8 )
Array ( [0] => 9 )
Array ( [0] => 10 )
Array ( [0] => 11 )
Array ( [0] => 12 )
Array ( [0] => 13 )
Array ( [0] => 14 )


Source: stackoverflow-php

How can I submit form data from a foreach loop?

This is my form:

<form action="update.php" method="post">
    
<button type="submit"> Submit</button> </form>

I insert data via Ajax:

 $.ajax({
     url: "data.php",
     data: {
         id: id,
     },
     type: "POST",
     success: function(data) {
         $("#data").html(data);
     }
 })

data.php:

<?php
$pdo = $db->prepare("SELECT * FROM data WHERE id = ?");
$pdo->execute(array($id));
while ($row = $pdo->fetch(PDO::FETCH_ASSOC))
    {
   ?>
   <input name="id[]" type="text" value="<?php echo $row['id'];?>">
   <input name="name[]" type="text" value="<?php echo $row['name'];?>">
<?php
}

As an Output I have for example:

2  Jim
3  Alan
5  Bob

Now in my update.php I want to update my data in the mySQL database:

<?php
foreach($_POST['id'] as $key => $value) {
    $id = $_POST['id'][$key];
    $name = $_POST['name'][$key];
    $pdo = $db->prepare("UPDATE data SET name=?, WHERE id=?;");
    $pdo->execute(array(
        $name,
        $id
    ));
        echo $id." ".$name;
}

As a result I expect to get again:

2  Jim
3  Alan
5  Bob

But what happens, I get only:

2  Jim


Source: stackoverflow-php