i have a 1D arrayA and a 2D arrayB.
arrayA[0] = 'D'
arrayA[1] = 'U'
arrayA[3] = 'R'
arrayA[4] = 'B'
arrayA[5] = 'S'
arrayA[6] = 'H'
arrayB[0][0] = 'D' arrayB[0][1] = 2
arrayB[1][0] = 'B' arrayB[1][1] = 1
arrayB[2][0] = 'R' arrayB[2][1] = 1
arrayB[3][0] = 'U' arrayB[3][1] = 1
arrayB[4][0] = 'H' arrayB[4][1] = 0
arrayB[5][0] = 'S' arrayB[5][1] = 0
arrayB[x][y] is sorted – based on y.
I have to create a new array using the letters, first giving priority on y from arrayB[x][y].
But there are some same values in y like, 1 three times and 0 two times.
In this situation similar values will be sorted according to arrayA.
and the new array will sort like :
D, U, R, B, S, H
How can i do it efficiently ?
thanks in advance
In the code below,
$stringcorresponds toarrayB[x][0],$weightcorresponds toarrayB[x][1]and$ordercorresponds toarrayA: