= 1; $j--) { $pos = array_search($j, $positions); $movement[] = ceil(($pos+1)/2).$lines[$pos%2]; } $movements[$id] = [ 'tables' => $tables, 'rounds' => $rounds, 'sets' => $sets, 'movement' => $movement, 'positions' => $positions ]; } 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)); ?>