This should work:
${'q'.$n} = $db->getQuery(true);
But I would suggest that using arrays is probably better:
$q[$n] = $db->getQuery(true);
Pregunta
I have tried:
$n=1;
$q$n = $db->getQuery(true);
etc...
$q.$n = $db->getQuery(true);
etc...
$q[$n] = $db->getQuery(true);
etc...
$q{$n} = $db->getQuery(true);
none of them will give me
$q1 = $db->getQuery(true);
I know its probably a loop thing but the file will only ever have one digit for $n.
eg: $n=1; only once in that file.
Thanks in advance for any help on this
Cheers Jonnypixel
Solución
This should work:
${'q'.$n} = $db->getQuery(true);
But I would suggest that using arrays is probably better:
$q[$n] = $db->getQuery(true);
Otros consejos
What you are describing is known as 'variable variables' in PHP. Here's the docs for it, and here's a working, tested example.
<?php
$q1 = "Just an example";
$n = 1;
//
$varname = "q$n"; // "q1"
echo "Value of $" . $varname . " is: " . ${$varname};
// writes:
// Value of $q1 is: Just an example
?>