Group first, 2nd, 3rd, etc posts by category terms

I’m still trying to determine exactly why this works, but it works. Still refining it and will post updates, but feel free anyone to improve upon this. It was modified from this post.

<?php
$a1 = get_posts(array(
   'post_type' => 'post',
   'posts_per_page' => '-1',
   'tax_query' => array(
       array(
           'taxonomy' => 'category',
           'field' => 'slug',
           'terms' => 'cat-1'
       )
   ),
   'fields' => 'ids' // only get post IDs.
));
$a2 = get_posts(array(
   'post_type' => 'post',
   'posts_per_page' => '-1',
   'tax_query' => array(
       array(
           'taxonomy' => 'category',
           'field' => 'slug',
           'terms' => 'cat-2'
       )
   ),
   'fields' => 'ids' // only get post IDs.
));
$a3 = get_posts(array(
   'post_type' => 'post',
   'posts_per_page' => '-1',
   'tax_query' => array(
       array(
           'taxonomy' => 'category',
           'field' => 'slug',
           'terms' => 'cat-3'
       )
   ),
   'fields' => 'ids' // only get post IDs.
));
$a4 = get_posts(array(
   'post_type' => 'post',
   'posts_per_page' => '-1',
   'tax_query' => array(
       array(
           'taxonomy' => 'category',
           'field' => 'slug',
           'terms' => 'cat-4'
       )
   ),
   'fields' => 'ids' // only get post IDs.
));
$count = 999;
$newArray = array();
for ($i = 0; $i < $count; $i++) {
   $newArray[] = $a1[$i];
   $newArray[] = $a2[$i];
   $newArray[] = $a3[$i];
   $newArray[] = $a4[$i];
}


$wp_query = new WP_Query(array(
   'post_type' => 'post',
   'post__in' => $newArray,
   'orderby' => 'post__in'
));

if ($wp_query -> have_posts()):
   while ($wp_query -> have_posts()):
       the_post(); ?>

    <div id="post-<?php the_ID(); ?>" class="entry">
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php the_excerpt(); ?>
    </div>


   <?php endwhile;
endif;
?>