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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:29:41+00:00 2026-06-08T13:29:41+00:00

I have a dinamic array of directories like this: array(4) { [0]=> string(34) C:\www\www\mb\core

  • 0

I have a dinamic array of directories like this:

array(4) {
  [0]=>
  string(34) "C:\www\www\mb\core"
  [1]=>
  string(59) "C:\www\www\mb\core\plugins\enabled\response"
  [2]=>
  string(56) "C:\www\www\mb\core\plugins\enabled\tests"
  [3]=>
  string(52) "C:\www\www\mb\core\templates\default"
}

And I have another directory to test: C:\www\www\mb\core\plugins\enabled\includes

I need to know what directory is the closest one to this one, by a function.
Everything here is unknown and dynamic.
I’ve tried with foreach+strpos+string size but it was becoming so ugly that I stopped and came here for help, and it didn’t work too. 😛

Thanks in advance and sorry for my bad English,

Vinicius

  • 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-08T13:29:44+00:00Added an answer on June 8, 2026 at 1:29 pm

    Well, I would do exactly what you described…

    function closest_path($path, $paths) {
        $maxMatch = null;
        $maxMatchLength = 0;
    
        foreach($paths as $item) {
            if(strlen($item) > $maxMatchLength && strpos($path, $item) === 0) {
                $maxMatch = $item;
                $maxMatchLength = strlen($item);
            }
        }
    
        return $maxMatch;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I need to make an dynamic array like this: I have a max
I have an array of strings that are formatted like this: $strings = array(
i would like create a array of structure which have a dynamic array :
I have a dynamic array of strings, the elements of which I would like
I have this 2d dynamic array and I want to pass it to a
I have created a function that creates a dynamic string array with dynamic string
I want to create a dynamic array that will look like this, using years:
I have a dynamic 3d array of numbers and currently I'm doing it like
So I have this 2d dynamic array which content I want to free when
i have a (dynamic) array, which in this example contains 4 sets of data

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.