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

  • Home
  • SEARCH
  • 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 8446735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:00:00+00:00 2026-06-10T10:00:00+00:00

i have a multidimensional array like this $role = array ( ‘Dashboard’ => null,

  • 0

i have a multidimensional array like this

$role = array (
                  'Dashboard' => null,
                  'Students' => 
                    array (
                      'Admission' => array ( 0 =>  'Entry' ,1 =>  'Review' , 2 =>  'Approved/Reject'
                       ),
                     'Search' => null,
                     'AdvanceSearch' => null,
                     'Courses' => null
                    ),
                  'HR' => array ('Settings' => null),
                  'Employee Management' => array ( 0 =>  'Entry',1 =>  'Association',2 =>  'Search' ),
                  'Employee Attendance' => null,
                  'Payroll' => array (0 =>  'Generate Pay Slip',1 =>  'Payroll Run' , 2 =>  'Payroll Revert',3 =>  'View Pay Slips'),
                  'Finance' => null,
                  'More' => null);

and i want to print this array result in my html as

Here is the wanted solution

i am trying to do this by using recursion but unable to do that as DIV are not properly closed ..
here is the code that i am trying in my html

<?php 

                             $child = 0;
                            function RecursiveWrite($array, $child ) {
                                $parent_array_size =  count($array);
                                foreach ($array as $key => $vals) {
                                    if(is_array($vals)){
                                        $inner_array_size = count($vals);
                                        echo "<div class='main clear'><input type='checkbox'/> ".$key." &nbsp; &nbsp; ";
                                        RecursiveWrite($vals,$child);
                                    }else{
                                        $child = 0;
                                        if(is_numeric($key)){
                                            echo " &nbsp; <div class='left'> &nbsp; &nbsp; <input type='checkbox' class=''/> ".$vals." &nbsp; &nbsp; </div></div>";
                                        }else{
                                            echo "<div class='clear'><input type='checkbox'/> ".$key." </div></div>";
                                        }
                                    }
                                    //
                                }
                            }
                            RecursiveWrite($role, $child);
                        ?>

here is working code

How can i get this Any suggestion … ?

  • 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-10T10:00:02+00:00Added an answer on June 10, 2026 at 10:00 am

    Your Problem is missing closing div after recursion
    Try this Function

    function RecursiveWrite($array, $child )
    {
        $parent_array_size =  count($array);
        foreach ($array as $key => $vals)
         {
            if(is_array($vals))
            {
                $inner_array_size = count($vals);
                echo "<div class='deep'><div class='extra'><input type='checkbox'/> ".$key."</div>";
                RecursiveWrite($vals,$child);
                echo "</div>";
            }
            else
            {
                if(is_numeric($key)){
                    echo "<span class='single'><input type='checkbox' class=''/> ".$vals."</span>";
                }else{
                    echo "<div class='single'><input type='checkbox'/> ".$key." </div>";
                }
    
            }
        }
    }
    

    Use This Css

    <style type="text/css">
        .parent {border: solid 1px #000;}
        .parent div {border: solid 1px #000; margin:5px;}
        .extra {border:0px !important;}
        .single {margin-left:10px !important; border:0px !important;}
        span.single {display:inline-block; margin-left:20px;}
    </style>
    

    Use this to call your Function

    <div class="parent"><? RecursiveWrite($role, $child);?></div>
    

    Put all the code Provided in one page with your array.

    For better Codding standard you should Septate your style html and php for this try your luck 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array like this: [ 'user 1' => [ ['item 4'
I have a multidimensional array that look like this: Array [1] => Array (
I have a multidimensional-array which looks like this: $array = ( [0] => array
I have a multidimensional array that looks something like this: ourThing = array( 'id'
I have a multidimensional array like this Array ( [1] => Array ( [product_id]
I have a multidimensional array that looks like this: Array ( [0] => Array
let's say I have a really complicated multidimensional array like this: Array ( [A]
I have a multidimensional array. The contents look like this in the debugger. The
I have a multidimensional array like this: array(2) { [1]=> array(3) { [eventID]=> string(1)

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.