Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php How to put a variable with in a variable

Tags:

variables

php

I have this code:

echo $b1[1][wood];   // It would say 100

But i want to change the 1 in $b1, for example:

$id = 1;
echo $b(The $id here)[1][wood];

I tried

echo $b'.$id.'[1][wood];  

But it didnt work. Does any one have any suggestions ?

Thanks

like image 240
user2421030 Avatar asked Jun 02 '26 08:06

user2421030


1 Answers

Try this:

$id = 1;
echo ${'b'.$id}[1]['wood'];
like image 88
Milan Babuškov Avatar answered Jun 04 '26 23:06

Milan Babuškov