Creating a new variable with a dynamic name can be tricky. Let's take a look at an example:
function preloader(imglist) {
var imgs = imglist.split("|");
for (i in imgs) {
var img_{i} = new Image;
img_{i}.src = imgs[i];
}
}
preloader("asd.jpg|qwe.jpg|dorama.png");
I attempted to use arrays, but encountered some challenges.
var qwe = new Array();
qwe[1] = "asd";
var qwe[1] = new Image;
In PHP, you have more flexibility when it comes to naming variables dynamically:
$var1 = "test";
$var2_{$var1} = "test last";
echo $var2_test;
echo $var2_{$var1};