title: How can I order an array in a specific order, which I define?
body: <p>I want to order an array in a specific order, which I define.</p>
  
  <p>I've started building a function to order those arrays, but I'm stuck and I have no clue how to solve it.</p>
  
  <p>My current code:</p>
  
  <pre><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;
                  }
  
              }
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>This is the current array:</p>
  
  <p><a href="https://i.stack.imgur.com/zwSnX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zwSnX.png" alt="enter image description here"></a></p>
  
  <p>And this is the expected output:</p>
  
  <p><a href="https://i.stack.imgur.com/a29ph.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a29ph.png" alt="enter image description here"></a></p>
  
  <p>Since I'm stuck with my current code above, I will try to isolate and simplify my problem and show it to you.</p>
  
  <p>So as a simple example I have an array like this:</p>
  
  <pre><code>$champions = [
      "A" =&gt; 1,
      "C" =&gt; 2,
      "F" =&gt; 3,
      "B" =&gt; 4,
      "G" =&gt; 5,
      "D" =&gt; 6,
      "E" =&gt; 7,
  ];
  </code></pre>
  
  <p>Now I want to define the order of that array, e.g. First key <code>F</code>, then <code>D</code> 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?</p>
  
  <p>Another twist to mention here is, that the order maybe has more elements than the array itself. E.g.</p>
  
  <pre><code>Order: C,D,A,B
  Array: A,B,C
  </code></pre>