jdubwelch Posted February 28, 2006 Share Posted February 28, 2006 I have a text file:[code]team [tab] rank[enter][/code]There are 8 teams in the text file. What I'm trying to do is loop through each team and assign each team in the list to a value so I can put it into my code later on in the script. Here's my code for getting the stuff out of the text file:[code]$filename = '../../https/hoopFix06/oakland.txt';$fp = fopen ($filename, "r") or die ("error");$data = fread ($fp, filesize($filename));fclose ($fp);$line = explode ("\n", $data);$i = count ($line); for ($n=0; $n<$i-1; $n++) { $teamData = explode ("\t", $line[$n]); $teamName = $teamData[0]; $teamRank = $teamData[1];}[/code]i want the first team to be labeled $a11a, the second team $a11b, the third team $a12a, the fourth team $a12b, etc. I don't know how to get those into the loop though. Quote Link to comment https://forums.phpfreaks.com/topic/3768-making-a-specific-variable-in-a-loop/ Share on other sites More sharing options...
kenrbnsn Posted February 28, 2006 Share Posted February 28, 2006 Is there a reason why you want names like that? Why not store the names and ranks in an array, where the team name would be in the index, and the rank is the value:[code]<?php$teams = array();$filename = '../../https/hoopFix06/oakland.txt';$data = file($filename); // reads the file into an arrayforeach($data as $line) { list($tn, $tr) = explode ("\t", trim($line)); $team[$tn] = $tr; }}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/3768-making-a-specific-variable-in-a-loop/#findComment-13096 Share on other sites More sharing options...
radius Posted February 28, 2006 Share Posted February 28, 2006 hum i'm not sure to understand what you want, by the way if you want to create variables on the fly you can do that$teamname = "a11a";$$teamname = "yo";${$teamname . $teamname} = "yoyo";then you have $a11a = "yo" and $a11aa11a = "yoyo" Quote Link to comment https://forums.phpfreaks.com/topic/3768-making-a-specific-variable-in-a-loop/#findComment-13097 Share on other sites More sharing options...
jdubwelch Posted March 1, 2006 Author Share Posted March 1, 2006 well i'm making a thing for the march madness basketball tournament coming up. i don't know what teams are going to be in the bracket yet, but I want to start making it. I was thinking if I just read the teams in from a text file, then it doesn't matter that there are no teams set in the bracket yet, because all i have to do is change 1 file. does that make sense? Is there a better way to do that? it's a 63 game tournament, with 64 teams participating in it. Right now I'm just trying to do a "mini" version to get it working... then I'll expand it. And if it's just reading from a text file, it'll be easy to expand. Or at least i think it does. Quote Link to comment https://forums.phpfreaks.com/topic/3768-making-a-specific-variable-in-a-loop/#findComment-13200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.