How to do this in PHP arrays

Hi friends !

I have a code

echo $array[1]->description;

But I want to convert it in something like this


$id = 1;
echo $array[$id]->description;

so that the array could take value from variable and display the result.
How it could be possible?

When I am doing these



echo $array[$id]->description;

echo $array["$id"]->description;


Both shows nothing…
I am worried…

$array[$id] should work. Are you sure that you’ve correctly created $array?


// yes this works correctly at my place 
echo $array[1]->description; 

// But this doesn't
$id = 1;
echo $array[$id]->description; 


Thanks sir, I applied this and now it worked.


$id = (int) '1';
echo $array[$id]->description; 

Thanks again sir.