title: How to return an array of courses and rooms where the room capacity is greater than or equal to the course enrollment
body: <p>I am struggling with how to return an array of courses that includes an array of rooms with a capacity that is greater than or equal to the course enrollment of each course. </p>
  
  <p>The following code returns an array in the structure I want, but only the last value. I have tried array_merge_recursive, and either get an error or only the last value again.</p>
  
  <p>I created the arrays like this:</p>
  
  <pre><code>global $wpdb;
  $course_query1 = new WP_Query( array( 'post_type' =&gt; 'courses', 'posts_per_page' =&gt; '-1' ) );
  $courses = $course_query1-&gt;posts;
  $course_array1 = array();
  
  foreach($courses as $i =&gt; $course) {
      $course_array1[$i]['course_name'] = $course-&gt;post_name;
      $course_array1[$i]['cap'] = $course-&gt;course_enrolled;
      $course_array1[$i]['cap_array'] = $course-&gt;room_matches;
  
  }
  
  $room_query1 = new WP_Query( array( 'post_type' =&gt; 'jost_rooms', 'posts_per_page' =&gt; '-1' ) );
  $rooms = $room_query1-&gt;posts;
  $room_array1 = array();
  
  foreach($rooms as $i =&gt; $room) {
          $room_array1[$i]['room_name'] = $room-&gt;post_name;
          $room_array1[$i]['cap'] = $room-&gt;room_capacity;
  
  }
  </code></pre>
  
  <p>And created the function like so:</p>
  
  <pre><code>function compare_capacities10($array1, $array2){
  
  for($c = 0; $c &lt; count($array1); $c++) {
  
      foreach($array1[$c] as $ckey =&gt; $ccap) {
                  if ($ckey == 'cap') {
  
                  for($r = 0; $r &lt; count($array2); $r++) {
                          foreach($array2[$r] as $rkey =&gt; $rcap) {
                              if (($rkey == 'cap') &amp;&amp; ($rcap &gt;= $ccap)){
                                  //this structure is right but only returns last value
                                  $result = array($ckey, $ccap, array($rkey, $rcap) );
                              }
                          }
                  }
              }
          }
      }
  return $result;
  }
  
  $capacity_array10 =  compare_capacities10 ($course_array1, 
  $room_array1);
  print_r($capacity_array10);
  </code></pre>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I'm adding the code below, because it's achieving the same thing as above, but is better in WordPress because I can add other key-values to the display: </p>
  
  <pre><code>  $courses = new WP_Query( array( 'post_type' =&gt; 'courses', 'posts_per_page' =&gt; '-1'  ) );
  
  
      if ( $courses-&gt;have_posts() ) {
        while ( $courses-&gt;have_posts() ) {
          $courses-&gt;the_post();
  
           $enr = get_post_meta(get_the_ID(), 'course_enrolled' , true);
           $cname = get_the_title();
  
           $rooms = new WP_Query(
                    array(
                    'posts_per_page' =&gt; -1,
                    'post_type' =&gt; 'rooms',
                    'meta_query' =&gt; array(
                          array(
                          'key' =&gt; 'room_capacity',
                          'posts_per_page' =&gt; '-1',
  
                          'value' =&gt; $enr,
                          'compare' =&gt; '&gt;='
                          )
                        )
                      )
            );
            if ( $rooms-&gt;have_posts() ) {
              while ( $rooms-&gt;have_posts() ) {
                  $rooms-&gt;the_post();
  
  
                  $rname = get_the_title();
                  $cap = get_post_meta(get_the_ID(), 'room_capacity' , true);
                  echo 'cname: ' . $cname . ' ' . 'enrolled: ' . $enr . 'rname: ' . $rname.  'capacity: ' . $cap . '&lt;br/&gt;';
  
                }
              }
  
        }
      } else {
          echo "Loop not working";
        }
  
     wp_reset_postdata();
  </code></pre>