title: PHP: Array sorting according to another array
body: <p>I have two arrays with around 50 fields each, one is an array of users, which was obtained from db and looks like this (shortened to only 3 fields)</p>
  
  <pre><code>Array( [0] =&gt; Array([id] =&gt; 1 [email] =&gt; email1@hotmail.com [last_name] =&gt; Lastname)
         [1] =&gt; Array([id] =&gt; 2 [email] =&gt; email2@hotmail.com [last_name] =&gt; Lastname2)
       );
  </code></pre>
  
  <p>My other array, is an array of fields, where key is the name of the field, and value is the field in the users table (shortened as well):</p>
  
  <pre><code>Array([User ID] =&gt; id [Last Name] =&gt; last_name [Email] =&gt; email);
  </code></pre>
  
  <p>Now, I want to produce an array to compare two users, and after a couple of foreach I got this array:</p>
  
  <pre><code> Array([id] =&gt; Array([0] =&gt; 1 [1] =&gt; 2)
            [email] =&gt; Array([0] =&gt; email1@hotmail.com [1] =&gt; email2@hotmail.com)
            [last_name] =&gt; Array([0] =&gt; Lastname [1] =&gt; Lastname2)
  </code></pre>
  
  <p>This last array, as you can see, contains the id for the two users, email for both, etc. which is used to make comparisons. This works, however, you can see that the order does not correspond to the names of the fields array. I would like the third array to be created according to the order of the second array (that is, 1) id, 2) last name, 3) email)</p>
  
  <p>How can that be achieved?</p>