Bài toán kinh điển lồng mảng của mảng (ok)

C:\xampp\htdocs\injagroup\wp-content\themes\houzez-child\template-parts\common-label.php

Xử lý code 👍)

<?php
$termchildrens          = get_terms($taxonomy_name, array('hide_empty' => false));
$ress = array();
foreach ($termchildrens as $_key => $_termchildrens) {
  if($_termchildrens->parent == $term_id) {
    $ress[$term_id][$_termchildrens->term_id][] = $_termchildrens;
    foreach ($termchildrens as $__key => $__arrr) {
      if($__arrr->parent == $_termchildrens->term_id) {
        $ress[$term_id][$_termchildrens->term_id]['child'][] = $__arrr;    
      }
    }
  }
  // if($_termchildrens->term_id == $_key) {
  //   $ress[$term_id][$_termchildrens->term_id]['child'][] = $_termchildrens;
  // }
}
echo '<pre>';
  var_export($ress);
echo '</pre>';
?>

C:\xampp\htdocs\code\test.php

8B
Open

Last updated

Was this helpful?