Jump to content

making a specific variable in a loop


jdubwelch

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/3768-making-a-specific-variable-in-a-loop/
Share on other sites

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 array
foreach($data as $line) {
    list($tn, $tr) = explode ("\t", trim($line));
    $team[$tn] = $tr; }
}?>[/code]

Ken
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.