sstangle73 Posted March 15, 2010 Share Posted March 15, 2010 i am trying to make a script that will make a varible 18 times here is what i have something is wrong for($i=1; $i<=18; $i++){ ${"player" . $i . "_number"} = ${$array[player . $i . _number]}; } it is something with the second half the ${$array[player . $i . _number]}; i am trying to get it so it will do: $player1_number = $array['player1_number']; $player2_number = $array['player2_number']; $player3_number = $array['player3_number']; ect Thanks! EDIT the error i am getting is Notice: Use of undefined constant player - assumed 'player' in /homepages/27/d193007783/htdocs/maddogmania/application/roster.php on line 22 Notice: Use of undefined constant _number - assumed '_number' in /homepages/27/d193007783/htdocs/maddogmania/application/roster.php on line 22 Notice: Undefined variable: 07 in /homepages/27/d193007783/htdocs/maddogmania/application/roster.php on line 22 the third one where it has the variable 07, 07 is what the $player1_number should be set to if it worked right Link to comment https://forums.phpfreaks.com/topic/195252-variable-variables/ Share on other sites More sharing options...
trq Posted March 15, 2010 Share Posted March 15, 2010 Assuming $array is an array. ${"player" . $i . "_number"} = $array['player' . $i . '_number']; You would be much better off using arrays instead of variable variables though. They are slow, and make your code much harder to read. Link to comment https://forums.phpfreaks.com/topic/195252-variable-variables/#findComment-1026124 Share on other sites More sharing options...
sstangle73 Posted March 15, 2010 Author Share Posted March 15, 2010 Thanks thorpe!! Link to comment https://forums.phpfreaks.com/topic/195252-variable-variables/#findComment-1026128 Share on other sites More sharing options...
Andy-H Posted March 15, 2010 Share Posted March 15, 2010 if you already have the array keys set as your desired variable names, as in thorpe's example; look into extract. Link to comment https://forums.phpfreaks.com/topic/195252-variable-variables/#findComment-1026129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.