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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:03:27+00:00 2026-05-23T17:03:27+00:00

Is there a way to access a multidimensional array from any position? example: $arr

  • 0

Is there a way to access a multidimensional array from any position? example:

$arr = array (

    1 => array ( 1, 'some-url-one', 'Some Title One' ),

    2 => array ( 2, 'some-url-two', 'Some Title Two' ),

    3 => array ( 2, 'some-url-three', 'Some Title Three' ),

);

Then, if we have the id of an item, for example 2 and want to get the title of that item we simply use:

$title = $arr[2][2]; // which outputs Some Title Two

And if we want to get the url of that same item we simply use:

$title = $arr[2][1];  // which outputs some-url-two

BUT what if we have the URL (some-url-two) and want to get the id or title of that item?

There are 2 obligations:

1- loop through the array and check if that URL exists
2- get the id and the title

How to do that the best way? I already have 3 arrays:

1- id to url

2- url to id

3- id to title

$id2url = array (

    1 => 'some-url-one',
    2 => 'some-url-two',
    3 => 'some-url-three'

);

And the two others are the same procedure. So I wanted to optimize my code by combining the 3 arrays. so how to access the id and the title with a given url?

Thanks.

  • 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-23T17:03:27+00:00Added an answer on May 23, 2026 at 5:03 pm

    You might look for array_flip() PHP Manual, it will make your lookup arrays work with their values as keys:

    $id2url = array (
    
        1 => 'some-url-one',
        2 => 'some-url-two',
        3 => 'some-url-three'
    
    );
    
    $url2id = array_flip($id2url); // keys will become values, and values keys.
    
    $id = $url2id[$url];
    
    $title = $arr[$id][2];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to access the Windows Event Log from a java class.
Is there any way to access let bound fields from a static member? The
Is there any way to access the current instance of CodeIgniter from an error
Is there some way to access the value of an MSBuild property from a
Is there any way to access a Windows hidden share from Cygwin? I've tried:
Is there any way to access the voicemail from the SDK. As I know
Is there any way to access the tables in a mysql embedded database from
is there any way to access parent page ViewState from the user control.
Is there any way to access a layout's view from a non-Activity-derived class? I'm
Is there a way to access the response headers from an HTTP result when

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.