Is it possible to create variable inside foreach loop that each variable name depend on column that I select?
Here is my code:
//sql select string declaration
$sql = "select [Rec_ID],[Bike_ID],[Station],['Line']
from [rfttest].[dbo].[RFT_Records_Log]
where [Rec_ID] = '{$_GET['recid']}'";
$query = sqlsrv_query($conn,$sql); //query
//if query fail print out error
if($query === false)
{
die(print_r(sqlsrv_errors(),true));
sqlsrv_close($conn);
}
//continue with fetch array
$recdata = sqlsrv_fetch_array( $query, SQLSRV_FETCH_ASSOC);
//foreach to declare variable
foreach($recdata as $x => $a)
{
$"$x" = $"$a";
}
In this code I should successfully declare variable like:
$Rec_ID , $Bike_ID , $Station , $Line
I still get a syntax error:
Parse error: syntax error, unexpected '"', expecting variable (T_VARIABLE) or '$'