Fe 我有对象 $game,有 3 个截图 $game->screen1, $game->screen2, $game->screen3
我需要得到这样的数据 $game['screen'.$num],但是在 Object.
Fe 我有对象 $game,有 3 个截图 $game->screen1, $game->screen2, $game->screen3
我需要得到这样的数据 $game['screen'.$num],但是在 Object.
你可以这样做:
$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"
您可以为此使用数组:
$game->screen = array($screen1, $screen2, $screen3);
$game->screen[$num];