将数据库数组作为隐藏表单值插入?

I need some help with this code.

In my code, I have the following hidden form fields as array:

Code:

<form action='final.php' method = 'POST'>
<input type="hidden" name="employeename" value="<?php echo $employeename; ?>">
<input type="hidden" name="ttitle" value="<?php echo $ttitle; ?>">
<input type="hidden" name="sourcename[]" value="<?php echo $_POST['sourcename' . $id]; ?>">
<input type="hidden" name="sourceaddress[]" value="<?php echo $_POST['sourceaddress' . $id]; ?>">
<input type="hidden" name="income[]" value="<?php echo $_POST['income' . $id]; ?>">
<input type="hidden" name="spousename[]" value="<?php echo $_POST['spousename' . $id]; ?>">
<input type="hidden" name="spouseAddress[]" value="<?php echo $_POST['spouseAddress' . $id]; ?>">
<input type="hidden" name="spouseIncome[]" value="<?php echo $_POST['spouseIncome' . $id]; ?>">
</form>

These hidden form fields are on a page called reviewe.php passed from pervious page called order.php.

I am trying to insert the values of these form fields from a page called finel.php as the action on the form indicates.

Code:

$sql = 'INSERT INTO `myDB`.`wp_myTable` ( `employeeID`'
     . ', `sourcename`, `sourceaddress`, `income`,`spousename`,`spouseAddress`,`spouseincome` )'
     . ' VALUES ( ? , ? , ? , ? , ? , ? , ? )';

if( $sth = mysqli_prepare($conn,$sql) ) {
   mysqli_stmt_bind_param($sth,'sssssss'
      ,$last_id
      ,$_POST["sourcename"]
      ,$_POST["sourceaddress"]
      ,$_POST["income"]
      ,$_POST["spousename"]
      ,$_POST["spouseAddress"]
      ,$_POST["spouseIncome"]
   );

When this code is excuted, I get this error:

Notice: Array to string conversion in c:\xampp\folder\final.php

I know this error means that I have hidden form fields I am trying to pass as an array but I am trying to insert them as string.

However, I don't know how to modify the code to accept the variables as array.

Any advice ? Thankyou.

You can get the value of the hidden inputs, while they are in an array, by simply getting the first index of the array.

if( $sth = mysqli_prepare($conn,$sql) ) {
     mysqli_stmt_bind_param($sth,'sssssss'
       ,$last_id
       ,$_POST["sourcename"][0]
       ,$_POST["sourceaddress"][0]
       ,$_POST["income"][0]
       ,$_POST["spousename"][0]
       ,$_POST["spouseAddress"][0]
       ,$_POST["spouseIncome"][0]
     );

You can use implode function to write the array as string by doing something like this:

implode(",", $array);

and then use explode function to read it back in an array like this:

explode(",", $array);