2
F.e. 我有對象$遊戲中,有3個截圖 $遊戲 - >屏蔽1,$遊戲 - >畫面2,$遊戲 - > SCREEN3如何使用變量從Object的字段中獲取數據?
我需要這樣$遊戲數據[ '屏幕'。$ NUM] ,但在對象中。
F.e. 我有對象$遊戲中,有3個截圖 $遊戲 - >屏蔽1,$遊戲 - >畫面2,$遊戲 - > SCREEN3如何使用變量從Object的字段中獲取數據?
我需要這樣$遊戲數據[ '屏幕'。$ NUM] ,但在對象中。
您可以使用這樣的數組:
$game->screen = array($screen1, $screen2, $screen3);
$game->screen[$num];
你可以做到這一點,像這樣:
$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"