How to create dynamic incrementing variable using "for" loop in php? like wise: $track_1,$track_2,$track_3,$track_4..... so on....
Why the downvote?
Alix Axel
2010-04-28 07:45:59
+1 for ${...} instead of variable variables.
Felix Kling
2010-04-28 07:48:29
${...} is still a variable variable.
Lotus Notes
2010-04-28 07:49:39
Y variable variables should be avoided?
OM The Eternity
2010-04-28 08:33:01
What If I need the Value of variable previuos than the current variable? That is, ${'track_' . $i-1} can I do this?
OM The Eternity
2010-04-28 08:49:53
Why do you want to do that? Likely you should use an array.
Lo'oris
2010-04-28 09:43:54
@Parth: You can but you should use it like this: `${'track_' . ($i - 1)}` to keep the concatenation and the arithmetic clearly separated.
Alix Axel
2010-04-28 11:15:05
+3
A:
<?
for($i = 0; $i < 10; $i++) {
$name = "track_$i";
$$name = 'hello';
}
print("==" . $track_3);
Palantir
2010-04-28 07:42:15