TABLE `people`
+----+------------+-------+
| sn | name | upper |
+----+------------+-------+
| 1 | Clement | 0 |
| 2 | Jean | 1 |
| 3 | Annie | 1 |
| 4 | Yuan | 2 |
| 5 | Mei | 2 |
| 6 | Blue | 3 |
| 7 | Yang | 5 |
| 8 | Lorinda | 0 |
+----+------------+-------+
The structure is like:
Clement
Jean
Yuan
Mei
Yang
Annie
Blue
Lorinda
The column upper states the upper person of himself/herself.
The problem is: How can I get a nested/multi-dimensional array from MySQL?
I thought I could use loops to fetch, but I failed to automated fetch all the lowers.
The array could be like this:
Array
(
[1]=>Array
(
[self]=>Clement
[2]=>Array
(
[self]=>Jean
[4]=>Array
(
[self]=>Yuan
)
[5]=>Array
(
[self]=>Mei
[7]=>Array
(
[self]=>Yang
)
)
)
[3]=>Array
(
[self]=>Annie
[6]=>Array
(
[self]=>Blue
)
)
)
[8]=>Array
(
[self]=>Lorinda
)
)
Since we don't know how many 'upper' persons does one have, the solution should be an automated function that build a complete array, not just for three or four dimension.
In other word, the function should deep into all the lower person from a top person.
Given your input as:
$input = array(
array('sn' => 1, 'name' => 'Clement', 'upper' => 0),
array('sn' => 2, 'name' => 'Jean', 'upper' => 1),
array('sn' => 3, 'name' => 'Annie', 'upper' => 1),
array('sn' => 4, 'name' => 'Yuan', 'upper' => 2),
array('sn' => 5, 'name' => 'Mei', 'upper' => 2),
array('sn' => 6, 'name' => 'Blue', 'upper' => 3),
array('sn' => 7, 'name' => 'Yang', 'upper' => 5),
array('sn' => 8, 'name' => 'Lorinda', 'upper' => 0),
);
using references you can build a tree with the following loop:
$map = array();
foreach ($input as $node) {
// init self
if (!array_key_exists($node['sn'], $map)) {
$map[$node['sn']] = array('self' => $node['name']);
}
else {
$map[$node['sn']]['self'] = $node['name'];
}
// init parent
if (!array_key_exists($node['upper'], $map)) {
$map[$node['upper']] = array();
}
// add to parent
$map[$node['upper']][$node['sn']] = & $map[$node['sn']];
}
print_r($map[0]);
demo: http://3v4l.org/vuVPu
Assuming the data is like this
$data = array(
array(1, 'Clement', 0),
array(2, 'Jean ', 1),
array(3, 'Annie ', 1),
array(4, 'Yuan ', 2),
array(5, 'Mei ', 2),
array(6, 'Blue ', 3),
array(7, 'Yang ', 5),
array(8, 'Lorinda', 0),
);
this recursive function might work:
function tree($data, $node) {
foreach($data as $e)
if($e[2] == $node[0])
$node['children'] []= tree($data, $e);
return $node;
}
Use it like this:
$tree = tree($data, array(0));
print_r($tree);
using a reference map
$input = array(
array('sn' => 1, 'name' => 'Clement', 'upper' => 0),
array('sn' => 2, 'name' => 'Jean', 'upper' => 1),
array('sn' => 3, 'name' => 'Annie', 'upper' => 1),
array('sn' => 4, 'name' => 'Yuan', 'upper' => 2),
array('sn' => 5, 'name' => 'Mei', 'upper' => 2),
array('sn' => 6, 'name' => 'Blue', 'upper' => 3),
array('sn' => 7, 'name' => 'Yang', 'upper' => 5),
array('sn' => 8, 'name' => 'Lorinda', 'upper' => 0),
);
$map = []; // map a reference by id for each item
foreach ($input as &$inp) {
$map[$inp['sn']] = &$inp;
}
foreach ($map as &$_inp) { // assign each item to its parent, with help of the map
if ($_inp['upper']) {
$map[$_inp['upper']]['children'] = &$map[$_inp['upper']]['children'] ?? [];
$map[$_inp['upper']]['children'][] = &$_inp;
}
}
$result = array_filter($map, fn($item) => !$item['upper']);
print_r($result);```
Related
I got this string below.
string(49) "02/12/2018 (Assessment 2) = /86= | Weight: 50.00%"
string(49) "02/12/2018 (Assessment 2) = 50.83/86= | Weight: 50.00%""
The first example don't show any number before the /, in this case I need to use 00.00 as the default value.
I need to get this information and put in an array like this one:
$dados[ "date" ] = "02/12/2018"
$dados[ "markOK" ] = "50"
$dados[ "markTotal" ] = "86"
$dados[ "weight" ] = "50.00"
Other examples:
string(49) "02/12/2018 (Assessment 2) = /86= | Weight: 50.00%"
string(59) "06/11/2018 (Assessment 2) = 22.40/35=32.00 | Weight: 50.00%"
string(49) "04/12/2018 (Assessment 2) = /60= | Weight: 50.00%"
string(59) "11/09/2018 (Assessment 2) = 27.00/40=33.75 | Weight: 50.00%"
string(59) "09/09/2018 (Assessment 2) = 30.00/30=50.00 | Weight: 50.00%"
string(59) "14/08/2018 (Assessment 2) = 31.00/40=38.75 | Weight: 50.00%"
string(59) "19/06/2018 (Assessment 2) = 63.00/72=43.75 | Weight: 50.00%"
string(59) "17/06/2018 (Assessment 2) = 45.00/45=50.00 | Weight: 50.00%"
string(59) "22/05/2018 (Assessment 2) = 11.00/55=10.00 | Weight: 50.00%"
Like this:
(?P<date>\d{2}\/\d{2}\/\d{4})[^=]+=\s(?P<markOK>\d+(?:\.\d+)?)?\/(?P<markTotal>\d+)[^:]+:\s(?P<weight>\d+(?:\.\d+)?)
Test online
It's actually pretty simple.
(?P<date>\d{2}\/\d{2}\/\d{4}) capture the date
[^=]+=\s skip everything not an equal then the equal and a space
(?P<markOK>\d+(?:\.\d+)?)? capture float (optional)
\/ the slash
(?P<markTotal>\d+) capture integer
[^:]+:\s skip everything not a colon then the colon and a space
(?P<weight>\d+(?:\.\d+)?) capture float
Update
$pattern = '/(?P<date>\d{2}\/\d{2}\/\d{4})[^=]+=\s(?P<markOK>\d+(?:\.\d+)?)?\/(?P<markTotal>\d+)[^:]+:\s(?P<weight>\d+(?:\.\d+)?)/';
if(preg_match($pattern, $str, $matches)){
var_export($matches);
}
If you want to clean up the matches array you can do it like this:
$str = '04/12/2018 (Assessment 2) = /60= | Weight: 50.00%';
$pattern = '/(?P<date>\d{2}\/\d{2}\/\d{4})[^=]+=\s(?P<markOK>\d+(?:\.\d+)?)?\/(?P<markTotal>\d+)[^:]+:\s(?P<weight>\d+(?:\.\d+)?)/';
if(preg_match($pattern, $str, $matches)){
$default = [
'date' => '00/00/0000',
'markOK' => '0.00',
'markTotal' => '0',
'weight' => '0.00'
];
$matches = array_filter($matches);
$matches = array_merge($default, array_intersect_key($matches, $default));
var_export($matches);
}
Try it online
Output
array (
'date' => '04/12/2018',
'markOK' => '0.00',
'markTotal' => '60',
'weight' => '50.00',
)
While using named capture groups certainly has purpose for this case, I find the syntax makes the pattern unnecessarily bloated and harder to read. After matching the substrings (notably the optional 2nd substring), you'll need to write a condition to replace the zero-length string with 00.00.
Here's what I recommend:
Code: (PHP Demo) (Regex Demo)
$strings = [
"02/12/2018 (Assessment 2) = /86= | Weight: 50.00%",
"06/11/2018 (Assessment 2) = 22.40/35=32.00 | Weight: 50.00%",
"04/12/2018 (Assessment 2) = /60= | Weight: 50.00%",
"11/09/2018 (Assessment 2) = 27.00/40=33.75 | Weight: 50.00%",
"09/09/2018 (Assessment 2) = 30.00/30=50.00 | Weight: 50.00%",
"14/08/2018 (Assessment 2) = 31.00/40=38.75 | Weight: 50.00%",
"19/06/2018 (Assessment 2) = 63.00/72=43.75 | Weight: 50.00%",
"17/06/2018 (Assessment 2) = 45.00/45=50.00 | Weight: 50.00%",
"22/05/2018 (Assessment 2) = 11.00/55=10.00 | Weight: 50.00%"
];
foreach ($strings as $string) {
if (!preg_match('~(\d\d/\d\d/\d{4})[^=]+= (\d+(?:\.\d+)?)?/(\d+)[^:]+: (\d+(?:\.\d+)?)~', $string, $m)) {
echo "No match for string: $string\n";
} else {
$results[] = ['date' => $m[1], 'markOK' => strlen($m[2]) ? $m[2] : '00.00', 'markTotal' => $m[3], 'weight' => $m[4]];
}
}
var_export($results);
Output:
array (
0 =>
array (
'date' => '02/12/2018',
'markOK' => '00.00',
'markTotal' => '86',
'weight' => '50.00',
),
1 =>
array (
'date' => '06/11/2018',
'markOK' => '22.40',
'markTotal' => '35',
'weight' => '50.00',
),
2 =>
array (
'date' => '04/12/2018',
'markOK' => '00.00',
'markTotal' => '60',
'weight' => '50.00',
),
3 =>
array (
'date' => '11/09/2018',
'markOK' => '27.00',
'markTotal' => '40',
'weight' => '50.00',
),
4 =>
array (
'date' => '09/09/2018',
'markOK' => '30.00',
'markTotal' => '30',
'weight' => '50.00',
),
5 =>
array (
'date' => '14/08/2018',
'markOK' => '31.00',
'markTotal' => '40',
'weight' => '50.00',
),
6 =>
array (
'date' => '19/06/2018',
'markOK' => '63.00',
'markTotal' => '72',
'weight' => '50.00',
),
7 =>
array (
'date' => '17/06/2018',
'markOK' => '45.00',
'markTotal' => '45',
'weight' => '50.00',
),
8 =>
array (
'date' => '22/05/2018',
'markOK' => '11.00',
'markTotal' => '55',
'weight' => '50.00',
),
)
I am confused. I don't know how to create a tree view in MySQL using stored procedure. I tried searching in Google and I don't understand how to query.
I have
deptid | dept_code | dept_name | parent_deptid
1 1 wadir Umum 0
2 101 bagian umum 1
3 10101 kepala umum 2
4 102 bagian privasi 1
5 1010101 SUb bagian Tu 3
6 1010102 bagian umum 3
and I want to make it like this
deptid | dept_code | dept_name | parent_deptid
1 1 wadir Umum 0
2 101 -bagian umum 1
3 10101 --kepala umum 2
5 1010101 ---Sub bagian Tu 3
6 1010102 ---bagian umum 3
4 102 -bagian privasi 1
Since department code pattern looks to be convenient, I didn't spent time on parent_id. According to your department code pattern, following should help.
Simply padding the dept code and getting the sortable uniform codes.
Change your tableName in query please.
SELECT *
FROM tableName
ORDER BY RPAD(dept_code, 5, '0')
EDIT: Actually if parent_deptid was the actual parent's id then you would have just needed to sort by parent_deptid, then dept_code. However, parent_deptid doesn't look like the corresponding parent's id but something like "depth" instead.
EDIT2: Sorry, your parent_deptid looks to be ok, just needed to see more data showing other parent ids too. So I missed it. All you need to sort as following:
SELECT *
FROM tableName
ORDER BY parent_deptid, dept_code;
EDIT3 - According to edited question: Back to my initial suggestion by changing the padded string length - Following is the most suitable solution for your data structure.
SELECT *
FROM tableName
ORDER BY RPAD(dept_code, 10, '0')
10 could be the max length of your dept_code.
Chnage your dept_code column type to VARCHAR and use next query
SELECT *
FROM tableName
ORDER BY dept_code
The following query will create a markup output:
SELECT group_concat(
CONCAT(
REPEAT(' ', (CHAR_LENGTH(t.dept_code) - 1) / 2),
'- ',
t.dept_name
)
ORDER BY t.dept_code
SEPARATOR '\n'
) AS markup
FROM Table1 t
sqlfiddle
Result:
- wadir Umum
- bagian umum
- kepala umum
- SUb bagian Tu
- bagian umum
- bagian privasi
Will be rendered to:
wadir Umum
bagian umum
kepala umum
SUb bagian Tu
bagian umum
bagian privasi
Update
To match the question update:
SELECT t.*,
CHAR_LENGTH(t.dept_code) - CHAR_LENGTH(REPLACE(t.dept_code, '0', '')) AS indent,
CONCAT(
REPEAT('-', CHAR_LENGTH(t.dept_code) - CHAR_LENGTH(REPLACE(t.dept_code, '0', ''))),
t.dept_name
) AS indented_name
FROM Table1 t
ORDER BY t.dept_code
sqlfiddle
Update 2
The benefit of your design is that you do not need a stored procedure for such tasks. See the dept_code as the full tree path with 0 as separator. 1010102 could also be written as 1/1/1/2. If designed correctly you can just order by dept_code. To get node depth you just need to count the separator (0) in the path (dept_code).
Update 3
If you want to create a recursive structure, you better do in a procedural language like PHP:
Store SQL result from a simple query (SELECT * FROM depts) into an array, which would look like:
// result from query: SELECT * FROM depts
$depts = array(
array( // row #0
'deptid' => 1,
'dept_code' => '1',
'dept_name' => 'wadir Umum',
'parent_deptid' => 0,
),
array( // row #1
'deptid' => 2,
'dept_code' => '101',
'dept_name' => 'bagian umum',
'parent_deptid' => 1,
),
array( // row #2
'deptid' => 3,
'dept_code' => '10101',
'dept_name' => 'kepala umum',
'parent_deptid' => 2,
),
array( // row #3
'deptid' => 4,
'dept_code' => '102',
'dept_name' => 'bagian privasi',
'parent_deptid' => 1,
),
array( // row #4
'deptid' => 5,
'dept_code' => '1010101',
'dept_name' => 'SUb bagian Tu',
'parent_deptid' => 3,
),
array( // row #5
'deptid' => 6,
'dept_code' => '1010102',
'dept_name' => 'bagian umum',
'parent_deptid' => 3,
),
);
Build a recursive structure with two foreach loops:
$nodes = array();
$roots = array();
// init nodes
foreach ($depts as $dept) {
$dept['childs'] = array(); // init childs
$nodes[$dept['deptid']] = $dept;
}
foreach ($depts as $dept) {
if ($dept['parent_deptid'] == 0) {
$roots[] = $dept['deptid']; // add root
} else {
$nodes[$dept['parent_deptid']]['childs'][] = $dept['deptid']; // add to parents chlids list
}
}
The arrays $roots and $nodes will look like:
$roots = array (0 => 1,);
$nodes = array(
1 => array(
'deptid' => 1,
'dept_code' => '1',
'dept_name' => 'wadir Umum',
'parent_deptid' => 0,
'childs' => array(
0 => 2,
1 => 4,
) ,
) ,
2 => array(
'deptid' => 2,
'dept_code' => '101',
'dept_name' => 'bagian umum',
'parent_deptid' => 1,
'childs' => array(
0 => 3,
) ,
) ,
3 => array(
'deptid' => 3,
'dept_code' => '10101',
'dept_name' => 'kepala umum',
'parent_deptid' => 2,
'childs' => array(
0 => 5,
1 => 6,
) ,
) ,
4 => array(
'deptid' => 4,
'dept_code' => '102',
'dept_name' => 'bagian privasi',
'parent_deptid' => 1,
'childs' => array() ,
) ,
5 => array(
'deptid' => 5,
'dept_code' => '1010101',
'dept_name' => 'SUb bagian Tu',
'parent_deptid' => 3,
'childs' => array() ,
) ,
6 => array(
'deptid' => 6,
'dept_code' => '1010102',
'dept_name' => 'bagian umum',
'parent_deptid' => 3,
'childs' => array() ,
) ,
)
Demo
Now you can write some recursive function to walk through the tree:
function getSubtreeHTMLList($deptsids, $nodes) {
$result = '<ul>';
foreach ($deptsids as $deptsid) {
$result .= '<li>';
$result .= $nodes[$deptsid]['dept_name'];
if (count($nodes[$deptsid]['childs'] > 0)) {
$result .= getSubtreeHTMLList($nodes[$deptsid]['childs'], $nodes);
}
$result .= '</li>';
}
$result .= '</ul>';
return $result;
}
echo getSubtreeHTMLList($roots, $nodes);
Created HTML:
<ul><li>wadir Umum<ul><li>bagian umum<ul><li>kepala umum<ul><li>SUb bagian Tu<ul></ul></li><li>bagian umum<ul></ul></li></ul></li></ul></li><li>bagian privasi<ul></ul></li></ul></li></ul>
Demo
Rendered:
wadir Umumbagian umumkepala umumSUb bagian Tubagian umumbagian privasi
I need help with an application I'm creating.
I have a table, looks kind like this:
+----+-----------+---------+
| id | parent_id | name |
+----+-----------+---------+
| 1 | null | test |
+----+-----------+---------+
| 2 | null | test2 |
+----+-----------+---------+
| 4 | 1 | test3 |
+----+-----------+---------+
| 5 | 2 | test4 |
+----+-----------+---------+
And now, I get all the data in one array. I would like to get kinda this structure (php array as an cascade):
array(
0 => array(
'id' => 1,
'parent_id' => null,
'name' => 'test',
'children' => array(
'id' => 4,
'parent_id' => 1,
'name' => 'test3'
)
),
1 => array(
'id' => 2,
'parent_id' => null,
'name' => 'test2',
'children' => array(
'id' => 5,
'parent_id' => 2,
'name' => 'test4'
)
)
)
So there will every entry with a "parent_id=null" be a parent, and every entry with an id in "parent_id" will be in a child array.
I started it like this:
$newArray = array();
foreach($names as $name) {
if($name['parent_id'] == null || $name['parent_id'] == 0) {
// entry is parent
$newArray[$name['id']] = $name['name'];
} else {
// entry is child
}
}
But here is also my end, I don't know how to do that. I think i have to use some kind of recursive loop function, but I don't know how to start.
Would be awesome if somebody could help me.
Kind regards,
Matt.
You can use a recursive function like this (I only added the code which is relevant for understanding):
function get_children($parentId) {
$array = array();
//Load/Find $children
foreach($children as $child) {
$array[] = array(
'id' => $child->id,
'name' => 'YourName',
'children' => get_children($child->id)
);
}
return $array;
}
If you save the data in such an array, it isn't necessary to save the parent_id, because you can get it by searching for the parent elements id.
Heres my table:
Table: category
----------------
id | category
------------------
1 | category1
2 | category2
3 | category3
4 | category4
5 | category5
-
Table: news
------------------------------
id | title | category_id
------------------------------
1 | title 1 | 1
2 | title 2 | 2
3 | title 3 | 4
4 | title 4 | 5
5 | title 5 | 3
6 | title 6 | 3
7 | title 7 | 2
8 | title 8 | 5
9 | title 9 | 1
10| title 10 | 4
11| title 11 | 1
12| title 12 | 2
how to get mysql result like this:
(note: each category (1-5) assigned with one title only, then repeat again the cycle of category.)
I have tried using `group by order by.
Category 1 ===
title 1
Category 2
title
Category 3
title 5
Category 4
title 3
Category 5
title 4
Category 1 ===
title 9
Category 2
title
category 3
title 6
category 4
title10
category 5
title 8
category 1 ===
title 11
category 2
title 12
If you want to build such format using PHP, alternatively, you could use a while loop to create it. Consider this example:
First off, you need to properly query those values together, you can use join
// SAMPLE => SELECT * FROM `category`
// LEFT JOIN `news` ON `news`.`category_id` = `category`.`id`
Sample Output: SQL HERE
Secondly, after getting the values, you need to order them, In this case, (1, 2, 3, 4, 5)
Consider this example:
$results_from_db = array(
array('id' => 1, 'category' => 'category1', 'title' => 'title 1', 'category_id' => 1),
array('id' => 1, 'category' => 'category1', 'title' => 'title 9', 'category_id' => 1),
array('id' => 1, 'category' => 'category1', 'title' => 'title 11', 'category_id' => 1),
array('id' => 2, 'category' => 'category2', 'title' => 'title 2', 'category_id' => 2),
array('id' => 2, 'category' => 'category2', 'title' => 'title 7', 'category_id' => 2),
array('id' => 2, 'category' => 'category2', 'title' => 'title 12', 'category_id' => 2),
array('id' => 3, 'category' => 'category3', 'title' => 'title 5', 'category_id' => 3),
array('id' => 3, 'category' => 'category3', 'title' => 'title 6', 'category_id' => 3),
array('id' => 4, 'category' => 'category4', 'title' => 'title 3', 'category_id' => 4),
array('id' => 4, 'category' => 'category4', 'title' => 'title 10', 'category_id' => 4),
array('id' => 5, 'category' => 'category5', 'title' => 'title 4', 'category_id' => 5),
array('id' => 5, 'category' => 'category5', 'title' => 'title 8', 'category_id' => 5),
);
$ids = array();
foreach($results_from_db as $value) {$ids[] = $value['id'];}
$ids = array_values(array_unique($ids));
sort($ids);
$needle_key = 0;
// build the data (kinda like recursive searching)
$data = array();
while(true) {
$current_value = array_shift($results_from_db);
if($current_value['category_id'] == $ids[$needle_key]) {
$data[] = $current_value;
$needle_key++;
if($needle_key > count($ids)-1) {
$needle_key = 0; // resetter
}
} else {
array_push($results_from_db, $current_value);
}
if(empty($results_from_db)) {
break;
}
}
?>
<!-- if you want to echo -- >
<?php foreach($data as $key => $value): ?>
<?php echo '<strong>'.$value['category'].'</strong><br/>'; ?>
<?php echo str_repeat(' ', 8) . $value['title'].'<br/><br/>'; ?>
<?php endforeach; ?>
Should output something like this: Sample Fiddle
category1
title 1
category2
title 2
category3
title 5
category4
title 3
category5
title 4
category1
title 9
category2
title 7
category3
title 6
category4
title 10
category5
title 8
category1
title 11
category2
title 12
This is a follow-up to Detect future duplicate values while iterating through MySQL results in PHP.
I have an SQL query which produces the results:
team_id division_id wins
-------------------------------
10 2 44
9 2 42
5 1 42
2 1 42
3 1 41
11 2 40
1 1 36
8 2 31
7 2 29
12 2 24
4 1 20
6 1 18
I'm trying to calculate a given team's overall and divisional rankings.
For example, team_id = 1:
Overall: 7
Divisional: 4
For team_id = 3:
Overall: 5
Divisional: 3
For team_id = 9:
Overall: T-2 //must indicate tie
Divisional: 2
As you can see from the linked previous question/answer, I can calculate the Overall rank just fine. The issue comes with calculating the divisional rank as well (including properly handling ties).
I've tried storing the results in a multi-dimensional array like $arr['wins']['division_id']['team_id'], such as...
44 => 2 => 10
42 => 1 => 5
2
2 => 9
41 => 1 => 3
40 => 11 => 2
...
But am stuck as to how to iterate through and get my two respective ranks, as well as detecting ties appropriately for each.
Try something like this:
// Dataset as defined on question
$arr = array(
array('team_id' => 10, 'division_id' => 2, 'wins' => 44),
array('team_id' => 9, 'division_id' => 2, 'wins' => 42),
array('team_id' => 5, 'division_id' => 1, 'wins' => 42),
array('team_id' => 2, 'division_id' => 1, 'wins' => 42),
array('team_id' => 3, 'division_id' => 1, 'wins' => 41),
array('team_id' => 11, 'division_id' => 2, 'wins' => 40),
array('team_id' => 1, 'division_id' => 1, 'wins' => 36),
array('team_id' => 8, 'division_id' => 2, 'wins' => 31),
array('team_id' => 7, 'division_id' => 2, 'wins' => 29),
array('team_id' => 12, 'division_id' => 2, 'wins' => 24),
array('team_id' => 4, 'division_id' => 1, 'wins' => 20),
array('team_id' => 6, 'division_id' => 1, 'wins' => 18));
$divisionTeam = array();
$divisionWins = array();
foreach($arr as $team) {
$divisionTeam[$team['division_id']][] = $team['team_id'];
$divisionWins[$team['division_id']][] = $team['wins'];
}
echo "<pre>";
foreach (array_keys($divisionTeam) as $division_id) {
$rank = 0;
$prevWins = -1;
echo "DIVISION $division_id \n";
foreach ($divisionTeam[$division_id] as $index => $team_id) {
if ($prevWins == $divisionWins[$division_id][$index]) {
echo $team_id . " T - " . $rank . "\n";
}
else {
$rank++;
echo $team_id . " " . $rank . "\n";
}
$prevWins = $divisionWins[$division_id][$index];
}
}
echo "</pre>";