How to general 4D, 3D and 2D number from 4 input numbers

I got stuck how to generate array like this from 4 input values.

enter image description here

As = first position = 12

Kop = second position = 34

Kepala = third position = 56

ekor = fourth position = 78

User will be able to any number into those position (input) or sometime some field can be blank.

I would like the those 4 input values combine together and form as 4D, 3D and 2D number. But make sure the position cannot be change and the generate number cannot duplicate.

Example:

  • number 1 and 2 are on first position ever.
  • number 3 and 4 are on second position ever.
  • number 5 and 6 are on third position ever.
  • number 7 and 8 are on fourth position ever.

Source code (PHP or JS) or Idea both are appreciated.