Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cmp($a, $b) {
- return strcomp($a['level4'], $b['level4']);
- }
- foreach ($rows as $i => $row) {
- if ($row['number'] > 1) {
- $lowestRow = 0;
- $lowest = 1000;
- foreach ($rows as $j => $row2) {
- $diff = array_intersect_assoc($row, $row2);
- if (array_key_exists('level1', $diff) && array_key_exists('level2', $diff) && array_key_exists('level3', $diff)) {
- if ($lowest > $row['number']) {
- $lowest = $row['number'];
- $lowestRow = $j;
- }
- }
- }
- $rows[$lowestRow]['number'] = 1;
- $oldLowestRow = $lowestRow;
- uksort($rows, 'cmp');
- foreach($rows as $j => $row2) {
- if ($j != $oldLowestRow) {
- $diff = array_intersect_assoc($row2, $rows[$lowestRow]);
- if (array_key_exists('level1', $diff) && array_key_exists('level2', $diff) && array_key_exists('level3', $diff) && array_key_exists('level4', $diff)) {
- $rows[$lowestRow]['value'] += $row2['value'];
- if ($row2['value'] != 'a') {
- $rows[$lowestRow]['total'] += $row2['total'];
- }
- if ($rows[$lowestRow]['value'] == 'a' && ($row2['value'] != 'a' && $row2['value'] != '*')) {
- $rows[$lowestRow]['value'] = $row2['value'];
- }
- unset($rows[$j]);
- } else {
- if (array_key_exists('level1', $diff) && array_key_exists('level2', $diff) && array_key_exists('level3', $diff)) {
- $lowestRow = $j;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement