I want to order an array in a specific order, which I define.
I've started building a function to order those arrays, but I'm stuck and I have no clue how to solve it.
My current code:
public function order_spells($champions) {
foreach(array_keys($champions) as $champion){
if(isset($champions[$champion]['Passive']) || isset($champions[$champion]['Q']) || isset($champions[$champion]['W']) || isset($champions[$champion]['E']) || isset($champions[$champion]['R'])) {
foreach(array_keys($champions[$champion]) as $Spell_Icon) {
if($Spell_Icon!='General'){
//echo $Spell_Icon;
}
}
}
}
}
This is the current array:
And this is the expected output:
Since I'm stuck with my current code above, I will try to isolate and simplify my problem and show it to you.
So as a simple example I have an array like this:
$champions = [
"A" => 1,
"C" => 2,
"F" => 3,
"B" => 4,
"G" => 5,
"D" => 6,
"E" => 7,
];
Now I want to define the order of that array, e.g. First key F
, then D
and so on... How can I change my above code to get it to work as I want it to ? Or how can I order this example array here?
Another twist to mention here is, that the order maybe has more elements than the array itself. E.g.
Order: C,D,A,B
Array: A,B,C