Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:08:02+00:00 2026-06-02T23:08:02+00:00

i have array+object like this. Array ( [0] => stdClass Object ( [tid] =>

  • 0

i have array+object like this.

Array
(
    [0] => stdClass Object
        (
            [tid] => 1
            [parent_id] => 0
            [language] => th
            [t_type] => category
            [t_name] => cat1
            [t_description] => 
            [t_uri] => cat1
            [t_uri_encoded] => cat1
            [t_uris] => 
            [meta_title] => 
            [meta_description] => 
            [meta_keywords] => 
            [childs] => Array
                (
                    [0] => stdClass Object
                        (
                            [tid] => 3
                            [parent_id] => 1
                            [language] => th
                            [t_type] => category
                            [t_name] => cat1.1
                            [t_description] => 
                            [t_uri] => cat1.1
                            [t_uri_encoded] => cat1.1
                            [t_uris] => 
                            [meta_title] => 
                            [meta_description] => 
                            [meta_keywords] => 
                            [childs] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [tid] => 5
                                            [parent_id] => 3
                                            [language] => th
                                            [t_type] => category
                                            [t_name] => cat1.1.1
                                            [t_description] => 
                                            [t_uri] => cat1.1.1
                                            [t_uri_encoded] => cat1.1.1
                                            [t_uris] => 
                                            [meta_title] => 
                                            [meta_description] => 
                                            [meta_keywords] => 
                                        )

                                )

                        )

                    [1] => stdClass Object
                        (
                            [tid] => 4
                            [parent_id] => 1
                            [language] => th
                            [t_type] => category
                            [t_name] => cat1.2
                            [t_description] => 
                            [t_uri] => cat1.2
                            [t_uri_encoded] => cat1.2
                            [t_uris] => 
                            [meta_title] => 
                            [meta_description] => 
                            [meta_keywords] => 
                        )

                )

        )

    [1] => stdClass Object
        (
            [tid] => 2
            [parent_id] => 0
            [language] => th
            [t_type] => category
            [t_name] => cat2
            [t_description] => 
            [t_uri] => cat2
            [t_uri_encoded] => cat2
            [t_uris] => 
            [meta_title] => 
            [meta_description] => 
            [meta_keywords] => 
        )

)

this array+object in json string

[{"tid":"1","parent_id":"0","language":"th","t_type":"category","t_name":"cat1","t_description":null,"t_uri":"cat1","t_uri_encoded":"cat1","t_uris":null,"meta_title":null,"meta_description":null,"meta_keywords":null,"childs":[{"tid":"3","parent_id":"1","language":"th","t_type":"category","t_name":"cat1.1","t_description":null,"t_uri":"cat1.1","t_uri_encoded":"cat1.1","t_uris":null,"meta_title":null,"meta_description":null,"meta_keywords":null,"childs":[{"tid":"5","parent_id":"3","language":"th","t_type":"category","t_name":"cat1.1.1","t_description":null,"t_uri":"cat1.1.1","t_uri_encoded":"cat1.1.1","t_uris":null,"meta_title":null,"meta_description":null,"meta_keywords":null}]},{"tid":"4","parent_id":"1","language":"th","t_type":"category","t_name":"cat1.2","t_description":null,"t_uri":"cat1.2","t_uri_encoded":"cat1.2","t_uris":null,"meta_title":null,"meta_description":null,"meta_keywords":null}]},{"tid":"2","parent_id":"0","language":"th","t_type":"category","t_name":"cat2","t_description":null,"t_uri":"cat2","t_uri_encoded":"cat2","t_uris":null,"meta_title":null,"meta_description":null,"meta_keywords":null}]

how to create nested ul li like this.

<ul>
  <li>cat1
    <ul>
        <li>cat1.1
            <ul>
                <li>cat1.1.1</li>
            </ul>
        </li>
        <li>cat1.2</li>
    </ul>
  </li>
  <li>cat2</li>
</ul>

this is what i have tried

echo list_nested_cat( $list_item );
function list_nested_cat( $list_item, $start = 0) {
    echo '<ul style="margin-left: 1em;">';
    foreach ( $list_item as $item ) {
        if ( isset( $item->childs ) && is_array( $item->childs ) ) {
            echo '<li>'.$item->t_name.'</li>';
            list_nested_cat($item->childs);
        } else {
            echo '<li>'.$item->t_name.'</li>';
        }

    }
    echo '</ul>';
}

but this function echo incorrect html nested ul li format.

ps. i create array object from the code of arnaud576875

PHP tree structure for categories and sub categories without looping a query

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:08:04+00:00Added an answer on June 2, 2026 at 11:08 pm

    This should get you started:

    It uses a recursive function; it calls itself.

    UPDATED

    Tested with the JSON object and fixed some errors

    <?php    
    
    echo make_ulli($object); 
    
    function make_ulli($array){
        if(!is_array($array)) return '';
    
        $output = '<ul>';
        foreach($array as $item){  
    
            $output .= '<li>' . $item->t_name;      
    
            if(property_exists($item, 'childs'))
                $output .= make_ulli($item->childs);
    
            $output .= '</li>';
    
        }   
        $output .= '</ul>';
    
        return $output;
    }
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have an array like this (below is the var_dump) array 0 => object(stdClass)[11]
I have various objects that look like this: Array ( [0] => stdClass Object
I have a vardump that looks like this: Array ( [0] => stdClass Object
I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
I have an array like this: object[] args and need to insert those args
I have an object that looks like this when outputted via a print_r Array
I have a object $images that looks like this: stdClass Object ( [0] =>
I have an array of object literals like this: var myArr = []; myArr[0]
As a service result I have this array: array(1) { [0]=> object(stdClass)#322 (2) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.