2

Fe 我有对象 $game,有 3 个截图 $game->screen1, $game->screen2, $game->screen3

我需要得到这样的数据 $game['screen'.$num],但是在 Object.

4

2 回答 2

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"
于 2013-08-06T13:46:04.810 回答
0

您可以为此使用数组:

$game->screen = array($screen1, $screen2, $screen3);

$game->screen[$num];
于 2013-08-06T12:46:41.500 回答