PHP Variable inside variable array?

Sicky321

New member
How would I go about getting this to work:

$cat2 = array('1','2');
$dog = '2';

echo $cat$dog[0]; //so that it would output "1", just like using "$cat2[0]" would. However in my dynamic situation I need the "2" in $cat2 to be a variable such as $dog.
 
I think this might help:

$animal = array (1 => "cat", 2 => array(1 => "dog", 2 = "rabbit"));

the output would be:

echo $animal['1'] ///= cat
echo $animal['2']['1'] ///= dog
echo $animal['2']['2'] ///= rabbit

if you're used to using arrays this should make sense, if not then you should read up on arrays.
 
Back
Top