Hi my question is about PHP variable variables.
Basically I want to store courseworks marks of n courseworks into n variables, such as cw1 and cw2 etc. Using variable variables how can I come with cw1, cw2 etc.
![]() ![]() ![]() |
|
add comment
|
![]() ![]() |
Use an array instead. |
||
![]() ![]() |
You should really use an array, as Gumbo wrote:
However, a solution to your problem:
|
|||
![]() ![]() |
Note that we're using the dollar sign around curly braces around a string. |
||
![]() ![]() |
Not entirely sure I understand the question, but you can do something like this:
If you have a large number of these, you may be better off using an array for them, with indexes based on the coursework. ie:
|
|||
![]() ![]() |
Variable variables work in this way
But i do not recommend doing this, since what if the value of $var changes, then you can no longer print out the 3rd line in this code. If you could elaborate more on what you want to do i think we could help you more. |
||