How to define array in php like array1[] array2[]
using for loop like instead of a1
or a2
I can write ai and its in for loop is it possible?
Like
for($i=0;$i<10;$i++)
{
$ai[$i]="hello'";
}
so I would like to say as like
a1[1]=Hello
How to define array in php like array1[] array2[]
using for loop like instead of a1
or a2
I can write ai and its in for loop is it possible?
Like
for($i=0;$i<10;$i++)
{
$ai[$i]="hello'";
}
so I would like to say as like
a1[1]=Hello
You can access variables dynamically using this:
${"a$i"}[$i] = 'hello';
You could use a dynamic var
$ai.$i[$i] = 'Hello';
or
$ai.$i[$your_index] = 'Hello';
but be careful when doing this .. in this case it is difficult to keep in control of the variables .. is easy to make a mistake