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 3437716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:05:57+00:00 2026-05-18T08:05:57+00:00

I have the following url /dir1/dir2/page.php I need to generate a an array of

  • 0

I have the following url /dir1/dir2/page.php

I need to generate a an array of the parent->child relation form the above url.

/dir1
    |
    |
    /dir2/
        |
        |
        page.php

eg :

array('dir1'=> array(
        'child' => array( 'dir2' => array(
                    'child' => array( 
                            'page' => array())))));

I tried using the recursive function but not able to figure out the logic.
Please let me know if you need some more explanation.

  • 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-05-18T08:05:57+00:00Added an answer on May 18, 2026 at 8:05 am

    Here’s a recursive method (sorry for lack of comments, it’s late):

    <?php
    $urls = array('/dir1/dir2/page.php', '/dir1/dir3/page');
    
    function url_to_array($url, $array=null) {
        if($array === null) {
            $array = array();
            $url_parts = explode('/', $url);
    
            return url_to_array($url_parts, $array);
        } else {
            if(count($url)) {
                $item = array_pop($url);
                if($item) {
                    if(!$array) {
                        $array = array('page' => $array);
                    } else {
                        $array = array($item => array('child' => $array));
                    }
                }
                return url_to_array($url, $array);
            } else {
                return $array;
            }
        }
    }
    
    $array = array();
    foreach($urls as $url) {
        $array = array_merge_recursive($array, url_to_array($url));
    }
    
    print_r($array);
    ?>
    

    It prints out:

    wraith:Downloads mwilliamson$ php recursive.php 
    Array
    (
        [dir1] => Array
            (
                [child] => Array
                    (
                        [dir2] => Array
                            (
                                [child] => Array
                                    (
                                        [page] => Array
                                            (
                                            )
    
                                    )
    
                            )
    
                        [dir3] => Array
                            (
                                [child] => Array
                                    (
                                        [page] => Array
                                            (
                                            )
    
                                    )
    
                            )
    
                    )
    
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following URL: http://somedomain.com/aa/search/search.php I want it to return 2 selections, that
I have the following URL: http://domain.com/index.php?m=feedback&cSubject=My Subject I want to have a rewrite rule
I have the following url. http://127.0.0.1/ci/index.php/admin/menus/edit/24 I want to get 24 from this to
I have the following url I need to support in my asp.net mvc project
how can i controls #! in url suppose i have the following url http://www.facebook.com/#!/video/video.php?v=1106030301789
I have following url http://domain/phpfile.php/something1-param1/something2-param2/somethin3-param3 Can i rewrite it with htaccess to http://domain/phpfile.php?something1=param1&something2=para2&something3=param3 also
I have the following URL: http://www.mysite.co.uk/?location=mylocation1 I need to get the value of location
I have the following URL structure which I need to match to and get
I have the following rule in htaccess: RewriteRule ^([a-zA-Z0-9\-\_]+)/?$ test.php?&url=$1 [L] My question is
I have the following code making a GET request on a URL: $('#searchButton').click(function() {

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.