@@ -250,6 +250,8 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
250
250
$ attributes = $ xmlMap [$ id ]['attributes ' ];
251
251
$ details_desc = $ xmlMap [$ id ]['details ' ];
252
252
253
+ $ entryCount = [];
254
+
253
255
$ jsonelements = ["segmentIdx " => $ segmentIdx , "segmentCode " => $ id ];
254
256
foreach ($ segment as $ idx => $ detail ) {
255
257
$ n = $ idx - 1 ;
@@ -269,6 +271,12 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
269
271
270
272
$ d_desc_attr = $ details_desc [$ n ]['attributes ' ];
271
273
274
+ if (!array_key_exists ($ d_desc_attr ['name ' ], $ entryCount )) {
275
+ $ entryCount [$ d_desc_attr ['name ' ]] = 0 ;
276
+ }
277
+
278
+ $ entryCount [$ d_desc_attr ['name ' ]]++;
279
+
272
280
$ jsoncomposite = [];
273
281
if (isset ($ details_desc [$ n ]['details ' ]) && $ detail !== '' ) {
274
282
$ sub_details_desc = $ details_desc [$ n ]['details ' ];
@@ -300,7 +308,16 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
300
308
} else {
301
309
$ jsoncomposite = $ detail ;
302
310
}
303
- $ jsonelements [$ d_desc_attr ['name ' ]] = $ jsoncomposite ;
311
+
312
+ if ($ entryCount [$ d_desc_attr ['name ' ]] === 1 ) {
313
+ $ jsonelements [$ d_desc_attr ['name ' ]] = $ jsoncomposite ;
314
+ } else {
315
+ if ($ entryCount [$ d_desc_attr ['name ' ]] === 2 ) {
316
+ $ jsonelements [$ d_desc_attr ['name ' ]] = [$ jsonelements [$ d_desc_attr ['name ' ]]];
317
+ }
318
+
319
+ $ jsonelements [$ d_desc_attr ['name ' ]][] = $ jsoncomposite ;
320
+ }
304
321
}
305
322
$ jsonsegment ['key ' ] = $ attributes ['name ' ];
306
323
$ jsonsegment ['value ' ] = $ jsonelements ;
0 commit comments