<?php
$subjectSlots = [
"tamil" => [1, 2, 3, 4, 5],
"english" => [4, 5, 6],
"maths" => [1, 5, 8],
"social" => [1, 2, 5],
"pt" => [1],
"hindi" => [3, 4, 7]
];
$requiredSubjects = ['tamil', 'tamil', 'pt', 'maths', 'maths', 'social', 'hindi', 'english'];
usort($requiredSubjects, function($a, $b) use ($subjectSlots) {
return $subjectSlots[$a] <=> $subjectSlots[$b];
});
var_export($requiredSubjects);
preferences:
55.45 ms | 402 KiB | 5 Q