Is there a way to name or define a variable based on the value of another variable?
I have a MySQL result set in $row.
I am trying to dynamically name a variable by appended the beginning of a variable with the value of $row as follows:
$sampleVar.$row = 'a string';
Fatal error: Only variables can be passed by reference in...
$sampleVar01 = '';
$sampleVar02 = '';
$sampleVar03 = '';
$sampleVar04 = '';
What you are looking for is called variable variables
$var = $sampleVar.$row $$var = 'a string';
After your edit, here's what you need to do:
$var = 'sampleVar' . $row; $$var = 'a string'; echo $sampleVar01;