使用PHP在列中显示数据

I'm trying to display some data in columns in php with wordpress. I have the next snippet to do that:

 $args = array(
     'taxonomy'     => $taxonomy,
     'orderby'      => $orderby,
     'show_count'   => $show_count,
     'pad_counts'   => $pad_counts,
     'hierarchical' => $hierarchical,
     'title_li'     => $title,
     'parent'       =>19,
     'hide_empty'   => $empty
);
$columnas=0;
$all_categories = get_categories( $args );
echo '<table><tr>';
foreach ($all_categories as $cat) {
  $category_id = $cat->term_id;       
   if((($columnas%4)!==0)and($columnas!==0)){
     echo '<td><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a></td>';
     $columnas=$columnas+1;     
     echo 'Las columnas son: '.$columnas.'<br/>';
   }else
   {
     echo 'Columnas es: '.$columnas;
     echo '<td><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a></td></tr><tr>';
   }


}
echo '</tr></table>';

So what I'm doing wrong?, I don't get what I want which is a table with four columns and many rows. Surely, it's a silly thing but I don't see it.

I assume you need to display the categories in 4 column. Is that so then this code will help you to show in 4 column table.

 $args = array(
 'taxonomy'     => $taxonomy,
 'orderby'      => $orderby,
 'show_count'   => $show_count,
 'pad_counts'   => $pad_counts,
 'hierarchical' => $hierarchical,
 'title_li'     => $title,
 'parent'       =>19,
 'hide_empty'   => $empty
 );
 $columnas=0;
 $all_categories = get_categories( $args );

 echo '<table><tr>';
 foreach($all_categories as $cat) {
    if(($columnas%4) == 0 && $columnas > 0)
        echo '</tr><tr>';
    else

    $category_id = $cat->term_id;
    echo '<td><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a></td>';
    $columnas++;
}
$cnt = (($columnas + 1)%4);
if($cnt > 0) {
    echo '<td colspan="' . (($columnas-1) - $cnt) . '"></td>';
}
echo '</tr></table>';

But my suggetion are you going to display it in 4X list gor for ul li. Easy to do the loop.

Thanks

here is working logic you just need to put your code in and I hope it will help you.

   $all_categories = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
    $html = '<table><tr>';
    $i = 0;

    foreach ($all_categories as $cat) {
        if (($i % 4) == 0 && ($i != 0)) {
            $html .="</tr><tr>";
        }
        $html .="<td>$cat</td>";
        $i++;
    }
    $html .= '</tr></table>';
    echo $html;