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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:19:35+00:00 2026-05-26T07:19:35+00:00

I have a URL like http://example.com/size/large/color/red . How can I convert the URL into

  • 0

I have a URL like http://example.com/size/large/color/red. How can I convert the URL into an associate array so that I end up with:

$my_array("size" => "large", "color" => "red");

Bear in mind, that the URL could look like http://example.com/color/red/size/large/type/round. So basically, the keys and values could be anything. But they key will always be followed by the value.

  • 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-26T07:19:36+00:00Added an answer on May 26, 2026 at 7:19 am
    $url = 'http://example.com/size/large/color/red';
    
    $path = trim(parse_url($url, PHP_URL_PATH), '/');
    $path_chunks = preg_split('/\/+/', $path);
    
    $arr = array();
    
    for($i = 0, $count = count($path_chunks); $i < $count; $i += 2)
    {
       $arr[$path_chunks[$i]] = $path_chunks[$i + 1];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a URL like this: http:\/\/www.example.com\/example in a string object. Can somebody tell
I have a url like the following: http://www.example.com/cat/دسته/page/2/ As you can see there is
I have URL like: http://example.com#something , how do I remove #something , without causing
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
Suppose I have a url like: http://example.com/get-users which returns a JSON object of all
i have a url like this http://example.com/blog/photos/photos/gallery/image/1 . And i need to remove the
I have a url that looks like this http://example.com/index.php ?con=something&met=meh What i'm trying to
I want to be able to take a URL like: http://www.example.com/valOne/valTwo/valThree/valFour/valFive and convert it
Given I have a URL like http://www.example.com/example.json And I would like to check the
I have an URL like this http://www.example.com/Data/image/office-dôn-sì-à.jpg I want to copy that file to

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.