I would like to give incrementing variable name to each post value and take the assigned variable and build array. The below is what I tried
$list = array();
$x = 0;
$prefix = '$var_';
foreach(array_slice($_POST, 1) as $test){
$x++;
$list[] = "{$prefix}{$x} = {$test};":
}
echo implode(" ", $list);
So if I had 4 values in the post, like 0, a, b, c
it would echo something like
$var_1 = a; $var_2 = b; $var_3 = c;
I would like to put all the three $vars in array like below and use their value. This is where I am stuck. Any help?
$vars = array($var_1, $var_2, $var_3)
What I'm trying to achieve is to insert dynamic data to table where I only know the table_name,
$stmt = $mydb->prepare($sql);//I am able to populate the $sql and $str
$stmt->bind_param($str, $vars);
$stmt->execute();