// --- 4. ページネーション & データ取得 --- $total_count = count($filtered_ids); $total_pages = ceil($total_count / $limit); $target_ids = array_slice($filtered_ids, $offset, $limit); $items = []; foreach ($target_ids as $id) { // インデックスの数値IDから MGS_ID(文字列)を引く $mgs_id = $id_to_mgs[$id] ?? null; if ($mgs_id) { $json_file = "{$details_dir}/{$mgs_id}.json"; if (file_exists($json_file)) { $item_data = json_decode(file_get_contents($json_file), true); if ($item_data) { // 確実に mgs_id をデータ内に保持させる $item_data['mgs_id'] = $mgs_id; $items[] = $item_data; } } } } // ...(アコーディオン集計部分は変更なし)... ?>