I have a problem in php, i want to re-index the value of an array according to their key in order to make each array have the same order to be able to easily compare them (to remove duplicates) and it should apply to any length of array remove duplicates.
For example A,C,B,D / D,B,C,A / C,A,B,D should ALL be be reordered to have the value A,B,C,D because the given list of character with their index is 0->A , 1->B, 2->C, 3->D
for instance let's say we have this array
Array(
[0] => Array (
[0] => S,
[1] => E,
[2] => Q,
[3] => A
)
)
and we have a given list of character with indexes( the character with the index they should have):
// index --> character ( array with real indexes)
$array_real_index = Array(
[0] => A,
[1] => C,
[2] => D,
[3] => B,
[4] => E,
[5] => Q,
[6] => R,
[7] => S
)
If character found index should be replace (if not the right one) with the correct one.
So the result should be:
Array (
[0] => A,
[1] => E,
[2] => Q,
[3] => S
)
Thanks for your future help.
usort
function or similar. – Voitcus Mar 11 '13 at 15:42