Question: 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();

```

Answer: 
I believe you're looking for the [**extract()**](http://ua2.php.net/manual/en/function.extract.php) function:

```
$list = array();
$prefix = 'var_';
$_POST = array("TEST",1,2,3,"XYZ"); // post example

$x = 0;
foreach(array_slice($_POST, 0) as $test) {
    $x++;
    $list[$prefix.$x] = "{$test}";
}
extract($list);
echo $var_1; // outputs TEST

// print_r($list);

/*
Array
(
    [var_1] => TEST
    [var_2] => 1
    [var_3] => 2
    [var_4] => 3
    [var_5] => XYZ
)
*/

```

\*Extreme caution should be exercised when using functions with `$_POST`, `$_GET`, `$_FILES`, etc.
A bad and dirty way of doing it (no security)

```
$list = implode("  ", $list);
eval($list)

```

Now, you have $var\_1, $var\_2 defined. :)

Beware, eval is dangerous, dont use it.