Q:

Trying to post array causes notice: Uninitialized string offset

I have the below form (excerpt)
 <tr>

        <td><?php echo "$navn";?><input type="hidden" name="historik[]" value="<?php echo "$navn";?>"></td>
        <td><?php echo "$primaereMuskelgruppe";?><input type="hidden" name="historik[]" value="<?php echo "$primaereMuskelgruppe";?>"></td>
        <td><?php echo "$sekundaereMuskelgruppe";?><input type="hidden" name="historik[]" value="<?php echo "$sekundaereMuskelgruppe";?>"></td>
        <td><?php echo "$redskab";?><input type="hidden" name="historik[]" value="<?php echo "$redskab";?>"></td>
        <?php
        switch ($antalReps) {
            case 'Alle':?>
        <td><?php echo "$vaegt12reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt12reps";?>"></td>
        <td><?php echo "$vaegt10reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt10reps";?>"></td>
        <td><?php echo "$vaegt8reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt8reps";?>"></td>
        <td><?php echo "$vaegt6reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt6reps";?>"></td>
                <?php break;?>
            <?php case 12:?>
        <td><?php echo "$vaegt12reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt12reps";?>"></td>
                 <?php break;?>
            <?php case 10:?>
        <td><?php echo "$vaegt10reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt10reps";?>"></td>
                 <?php break;?> 
        <?php case 8:?>
        <td><?php echo "$vaegt8reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt8reps";?>"></td>
                 <?php break;?> 
             <?php case 6:?>
        <td><?php echo "$vaegt6reps";?><input type="hidden" name="historik[]" value="<?php echo "$vaegt6reps";?>"></td>
                 <?php break;
                            }
        ?>
        <td><?php echo "$inkrementering";?><input type="hidden" name="historik[]" value="<?php echo "$inkrementering";?>"></td>
        <td><input type="text" name="historik[]"><br></td>

        <?php 

             } 
             }
                ?>
    </tr>
</table>           
   <input type="submit" value="Gem træning" name="submit">
</form>

The form table can have 1-->many rows. All columns except the last one is read-only.
When the user clicks submit, I want it to post to a different page with a number of 'historik'-arrays, one for each row.
And then, on the next page, I want to go through each array like:
foreach ($_POST['historik'] as $historikArray)
{
    echo $historikArray;

When I do the above, the output seems ok - I get what looks like an array of data for each row in previous form.
But, when I do something like this:
foreach ($_POST['historik'] as $historikArray)
{
    echo $historikArray[3];

I would expect it to run through each array (i.e each row from previous form) and display array item number 3 for each array.
Instead, it echoes the third character of every piece of data from each field of each row/array, along with a notice. Below I've posted two rows from the table, with the 3rd character of each field in each row...
n
s
c
g
0
0

Notice: Uninitialized string offset: 3 in D:\Programmer\Xampp\htdocs\styrkesite\modtagHistorik.php on line 16

s
s
c
n
0
0

Notice: Uninitialized string offset: 3 in D:\Programmer\Xampp\htdocs\styrkesite\modtagHistorik.php on line 16

Apparently, I'm posting a string for each row, and not an array(?)
Can anyone help? Also, ideally I would like to use an associative array, but I don't know how to in this case...

A:

You are indeed posting strings. You cant post arrays. You can first serialize the array to a string then unserialize it after the post.
change:
<td><?php echo "$navn";?><input type="hidden" name="historik[]" value="<?php echo "$navn";?>"></td>

To:
<td><?php echo "$navn";?><input type="hidden" name="historik[]" value="<?php echo base64_encode(serialize($navn));?>"></td>

Then in your loop:
foreach ($_POST['historik'] as $historikArray)
    {
    echo unserialize(base64_decode($historikArray))[3];

