创建多维数组

How about, I entered a series of numbers in a doing the separation by means of a comma (,) When we press the SEND button, each of those numbers is entered into the BD, with a different ID. Example: We enter values = 5,6,7,8,9

In the BD they are saved in this way:

Id  values
1      5
2      6 
3      7
4      8
5      9

What I want is to add an Example: Enter the values = 5,6,7,8,9

We enter the cost = 100

I want that when entering the series [5,6,7,8,9] What cost to them is the cost = 100

That is, in the BD be saved in this way:

Id   values cost
1   5      100
2   6      100
3   7      100
4   8      100
5   9      100

Code:

Index.php

<html>

<head>
<title></title>
<meta name="robots" content="noindex, nofollow" />
</head>

<body>

<form method="POST" action="process_values.php">

    <p><textarea rows="20" name="values" cols="40"></textarea></p>

    <input type="text" name="cost" value="" placeholder="cost">

    <p><input type="submit" value="Submit" name="B1"></p>
</form>

</body>

</html>

process_values.php

<?php
error_reporting(-1);
ini_set("display_errors", 1);


$value = $_POST["values"];        //We receive textarea values

$valore = chop($value);    // Eliminate line breaks and space, but only at the end of the chain

$val = nl2br($valore);         // We add the line breaks <br />

$array_datos = explode(",", $val);   // Create an array with the received data using as a separator (,)


    foreach ($array_datos as $value)         // We create a foreach loop
    {

      include("$_SERVER[DOCUMENT_ROOT]/CN/connexion.php");

    $_SAVE_SQL = "INSERT INTO nombre_tabla (values) VALUES ('".$value."')";
    $mysqli->query($_SAVE_SQL);

    }

?>
<html>


<body>

</table>

<table border="1" width="600" id="table1">
    <tr>
        <td>ID</td>
        <td>VALUES</td>
    </tr>
<?PHP
/*******************************************************************************
* CONSULTING DATA TO THE BD
*******************************************************************************/
if ($res = $mysqli->query("SELECT * FROM table_name ORDER BY id ASC", MYSQLI_USE_RESULT)) {
  /*******************************************************************************
  * The while loop that runs through each record and shows each field in the table.
  *******************************************************************************/
  while ($row = mysqli_fetch_array($res)){
    echo "
        <tr>
            <td>".$row['id']."</td>
            <td>".$row['values']."</td>
        </tr>

    ";
  }
}
?>

</body>

</html>

It's confusing as on the above table you have mentioned values as 5,6,7,8,9 and in below table you have made it cost.

As per question I think you need something like

Id  values cost
1   5      100
2   6      100
3   7      100
4   8      100
5   9      100

Add it below where you are getting Values

$cost = $_POST["cost"];

Just modify your SQL query(considering you have column cost added in database): $_SAVE_SQL = "INSERT INTO nombre_tabla (values,cost) VALUES ('".$value."',$cost)";

First get the value of the cost at POST variable like this:

 $value = $_POST["values"];  
 $cost = $_POST["cost"];

then, you can iterate through the values and append the cost to each one, something like this:

$statement = "INSERT INTO (values, cost) VALUES ";
foreach($values as $item){

    $statement .= " ('".$item."', ".$cost.")" ;

}

$statement = substr($statement, 0, strlen($statement));
$mysqli->query($statement);