title: Does this array algorithm have a name?
body: <p>I'm trying to match up two different types of users (males and females), maybe I'm going about this the wrong way but it's like this:</p>
  <p>Users of type male: [A, B, C, D, E ...]<br />
  Users of type female: [1, 2, 3, 4, 5 ...]</p>
  <p>Both arrays will always be the same size.  I want to match the first type with the second type (each one has a unique identifier).  The output should be like below multidimensional array where the key is male and value is female:</p>
  <p>The items are objects of users from a DB.</p>
  <pre><code> 1: [
    [A, 1], [B, 2], [C, 3], [D, 4], [E, 5]
   ]
   2: [
    [A, 2], [B, 3], [C, 4], [D, 5], [E, 1]
   ]
   3: [
    [A, 3], [B, 4], [C, 5], [D, 1], [E, 2]
   ]
   4: [
    [A, 4], [B, 5], [C, 1], [D, 2], [E, 3]
   ]
   5: [
    [A, 5], [B, 1], [C, 2], [D, 3], [E, 4]
   ]
  </code></pre>
  <p>If it helps, each of these users belong to the same DB table of users, one type are male and one type are female.  I intend on turning this into a request/response type method so that it returns a json object of the array matrix.  I do not need any help with APIs or anything like that, I just need help with the core algorithm.</p>
  <p>If you do not wish to provide an answer, please can you provide the name of the formula so I can research it? Or pseudocode, and I'll write it up myself.  Many thanks.</p>
  <h2>Edit</h2>
  <p>Here is an attempt but it's not giving the expected outcomes and it is taking almost 2 seconds :O <a href="https://sandbox.onlinephpfunctions.com/code/cfe00576cb77eb23d0e094cac5961689c85b2442" rel="nofollow noreferrer">https://sandbox.onlinephpfunctions.com/code/cfe00576cb77eb23d0e094cac5961689c85b2442</a></p>
  <h2>Edit 2</h2>
  <p>I didn't realise it would be more complex than I thought, now I'm looking another output that would need to be valid (i.e. null values because sometimes we need to make it so that males or females don't have a match)</p>
  <pre><code>[
    0=&gt; [
      &quot;a&quot;=&gt; &quot;k&quot;, &quot;b&quot;=&gt; &quot;l&quot;, &quot;c&quot;=&gt; &quot;m&quot;, &quot;d&quot;=&gt; &quot;n&quot;, &quot;e&quot;=&gt; &quot;o&quot;, &quot;f&quot;=&gt; &quot;p&quot;, &quot;g&quot;=&gt; &quot;q&quot;, &quot;h&quot;=&gt; &quot;r&quot;, &quot;i&quot;=&gt; NULL, &quot;j&quot;=&gt; NULL
    ]
    1=&gt; [
      &quot;a&quot;=&gt; &quot;l&quot;,&quot;b&quot;=&gt; &quot;m&quot;, &quot;c&quot;=&gt; &quot;n&quot;, &quot;d&quot;=&gt; &quot;o&quot;, &quot;e&quot;=&gt; &quot;p&quot;, &quot;f&quot;=&gt; &quot;q&quot;, &quot;g&quot;=&gt; &quot;r&quot;, &quot;h&quot;=&gt; NULL, &quot;i&quot;=&gt; NULL, &quot;j&quot;=&gt; &quot;k&quot;
    ]
    ...etc...
  ]
  </code></pre>
  <p>In this new output example the assume the key is male and the value is female.  BUT it doesn't have to be, I'm merely just wanting a resultset I can use that has a male and a female match.</p>
  <p>I have also tried as suggested: <a href="https://sandbox.onlinephpfunctions.com/code/9fb0120c57a766bc383f64712c54557c3d1b00e7" rel="nofollow noreferrer">https://sandbox.onlinephpfunctions.com/code/9fb0120c57a766bc383f64712c54557c3d1b00e7</a> but same problem again it is taking too long, it takes average 1.5 seconds.</p>
  <p>If we turned it into an API, it would have a massive impact if all the requests kept taking a few seconds all the time perhaps more since over the internet.</p>