= 1; $j--) { // tyle par ruchomych, ile rund $pos = array_search($j, $positions); // odnajdujemy pary ruchome w kolejności X, X-1, ..., 2, 1 $movement[] = ceil(($pos+1)/2).$lines[$pos%2]; // i ich pozycję w tablicy $positions tłumaczymy na pozycję na sali (xN/E), tworząc wstęgę rotacji } // pozostałe pary - z automatu stacjonarne // kompilujemy strukturę $movements[$id] = [ 'tables' => $tables, 'rounds' => $rounds, 'sets' => $sets, 'movement' => $movement, 'positions' => $positions ]; } // segmenty nieparzyste to dane ogólne - liczba rund i stołów else { $matches = []; preg_match('/.*(-\d+).*RUNDY.*?(\d+).*STOLIKI.*/s', $file[$i], $matches); $id = $matches[2].$matches[1]; $tables = (int)($matches[2]); $rounds = -(int)($matches[1]); } } file_put_contents('movements.json', json_encode($movements)); ?>