Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = ["Germany / Argentina: 1-0",
- "Brazil / Netherlands: 0-3",
- "Netherlands / Argentina: 0-0",
- "Brazil / Germany: 1-7",
- "Argentina / Belgium: 1-0",
- "Netherlands / Costa Rica: 0-0",
- "France / Germany: 0-1",
- "Brazil / Colombia: 2-1"];
- $results = [];
- foreach ($input as $match) {
- $match = preg_split("/[\/:-]+/", $match);
- if (isset($results[$match[0]])) {
- $results[$match[0]]['Matches Against'] .= $match[1];
- $results[$match[0]]["Goals"] += (int)$match[2];
- $results[$match[0]]["Goals Against"] += (int)$match[3];
- }
- else {
- $results[$match[0]]['Matches Against'] = $match[1];
- $results[$match[0]]["Goals"] = (int)$match[2];
- $results[$match[0]]["Goals Against"] = (int)$match[3];
- }
- }
- ksort($results);
- foreach ($results as $match => $value) {
- echo json_encode($match) . json_encode($value) . "<br>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment