Reputation: 261
I've an array
Array ( [0] => value1 [1] => value2 [2] => value3 [(n)] => .....)
I want this as following:
$string1 = 'value1';
$string2 = 'value2';
$string3 = 'value3';
$string(n) = '....';
Please suggest the right way to get this.
Upvotes: 1
Views: 70
Reputation: 18600
You can use PHP extract() function.
extract($var_array, EXTR_PREFIX_ALL, "string");
Upvotes: 1
Reputation: 492
Does this work for what you need?
foreach($array as $key => $row) {
$var = "string" . $key;
$$var = $row;
}
But you said you need to do a query with the values. Maybe something like this?
$sql = "SELECT * FROM mytable WHERE 1 = 1";
foreach($array as $key => $row) {
$sql .= " AND string" . $key . " = '" . $row . "'";
}
Upvotes: 0