F.e。 我有对象$游戏,有3个截图 $ game-> screen1,$ game-> screen2,$ game-> screen3
我需要获取类似这个$ game ['screen'。$ num]的数据,但是在Object中。
答案 0 :(得分:0)
您可以使用数组:
$game->screen = array($screen1, $screen2, $screen3);
$game->screen[$num];
答案 1 :(得分:0)
你可以这样做:
$game->screen2 = 'this is screen2';
$num = 2;
echo $game->{'screen' . $num}; // "this is screen2"
$game->screen3 = 'this is screen3';
$num = 3;
echo $game->{'screen' . $num}; // "this is screen3"