Create a trailing block with programatically generated Gutenberg columns

I’ve currently “solved” this by backfilling with empty divs:

$array_chunks = array_chunk($array_of_posts, 3);
foreach($array_chunks as $posts) {
  echo '<div class="wp-block-columns">';
  foreach($posts as $post) {
    echo '<div class="wp-block-column">';
      // entry
    echo '</div>';
    for ($i = 0; $i < ( 3 - count($posts)); $i++) {
      echo '<div class="wp-block-column">';
      echo '</div>';
    }
  }
  echo '</div>';
}

But that seems a little clunky. I’d love a more elegant solution.