Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = ["ZZ Top | London | 2-Aug-2014 | Wembley Stadium",
- "Iron Maiden | London | 28-Jul-2014 | Wembley Stadium",
- "Metallica | Sofia | 11-Aug-2014 | Lokomotiv Stadium",
- "Helloween | Sofia | 1-Nov-2014 | Vassil Levski Stadium",
- "Iron Maiden | Sofia | 20-June-2015 | Vassil Levski Stadium",
- "Helloween | Sofia | 30-July-2015 | Vassil Levski Stadium",
- "Iron Maiden | Sofia | 26-Sep-2014 | Lokomotiv Stadium",
- "Helloween | London | 28-Jul-2014 | Wembley Stadium",
- "Twisted Sister | London | 30-Sep-2014 | Wembley Stadium",
- "Metallica | London | 03-Oct-2014 | Olympic Stadium",
- "Iron Maiden | Sofia | 11-Apr-2016 | Lokomotiv Stadium",
- "Iron Maiden | Buenos Aires | 03-Mar-2014 | River Plate Stadium"];
- $concerts = [];
- for ($i=0; $i < count($input); $i++) {
- $row = explode(" | ", $input[$i]);
- for ($j=0; $j < count($row); $j++) {
- if (isset($concerts[$row[1]])) {
- if (isset($concerts[$row[1]][$row[3]])) {
- if (in_array($row[0], $concerts[$row[1]][$row[3]])) {
- continue;
- }
- else {
- array_push($concerts[$row[1]][$row[3]], $row[0]);
- }
- }
- else {
- $concerts[$row[1]][$row[3]] = [];
- array_push($concerts[$row[1]][$row[3]], $row[0]);
- }
- }
- else {
- $concerts[$row[1]] = [];
- $concerts[$row[1]][$row[3]] = [];
- array_push($concerts[$row[1]][$row[3]], $row[0]);
- }
- }
- }
- ksort($concerts);
- foreach ($concerts as $key => $value) {
- ksort($concerts[$key]);
- foreach ($concerts[$key] as $inner => $value) {
- sort($concerts[$key][$inner]);
- }
- }
- echo json_encode($concerts);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment