hexagon logo

Multi Dimensional Array to Single Dimension Array

Here's something I always seem to forget when I need it and have to think a little bit to remember (so why not document it here for my future self ps. you're memory is deteriorating quickly future self!).

            ASSIGN/ARRAY_1=ARRAY({PNT69},{CIR16},{CIR17})
            ASSIGN/ARRAY_2=ARRAY({LIN12},{PLN6},{PLN7},{PLN8},{LIN13})
            ASSIGN/ARRAY_3=ARRAY({LIN14},{PLN9},{PLN10},{PLN11},{LIN15})
$$ NO,
            load as many arrays into below vvvv
            ASSIGN/MULTI_ARRAY=ARRAY(ARRAY_1,ARRAY_2,ARRAY_3)
$$ NO,
            Push all items in multi dimensional array into a single dimensional array.
            
            ASSIGN/SINGLE_ARRAY=0
            ASSIGN/CNT=1
            ASSIGN/O_CNT=1
            DO/
            ASSIGN/I_CNT=1
            DO/
            ASSIGN/SINGLE_ARRAY[CNT]=MULTI_ARRAY[O_CNT,I_CNT]
            ASSIGN/CNT=CNT+1
            ASSIGN/I_CNT=I_CNT+1
            UNTIL/I_CNT > LEN(MULTI_ARRAY[O_CNT])
            ASSIGN/O_CNT=O_CNT+1
            UNTIL/O_CNT > LEN(MULTI_ARRAY)


You super users out there.. if you know a quicker, simpler, easier way to do this I would greatly appreciate it if you shared it below.
Parents Reply Children
No Data