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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:09:28+00:00 2026-06-06T01:09:28+00:00

Yet another PHP question. I’ve got two arrays: one string-based and the other numeric.

  • 0

Yet another PHP question. I’ve got two arrays: one string-based and the other numeric. The array of strings contains the names of various buildings. The numeric array tracks relevance of the search in relation to the buildings.

Example: I search for “Armory Building” (http://yoursite.com/search.php?building=Armory+Building)

I loop through all 25 buildings and display any containing one or more search terms (Armory and Building).

Armory Hall
Armory State Building
Armory Dining Hall Building

Obviously, if the search should bring up results based on relevance, the last two should appear FIRST. How do I sort it so that both arrays get re-ordered but maintain the same index, meaning I re-order the results based on relevance (the last 2 would have a “relevance” of 2 and the first result would have a “relevance” of 1).

  • 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-06T01:09:31+00:00Added an answer on June 6, 2026 at 1:09 am

    In this case its not easy to do this. If you have 2 arrays, and you sort one of them, you need in the same time sort the other one and if elements has chenge, related elements need to be changed in 2nd array.

    Better way is to keep all in one 2 dimensions array and sort it:
    https://www.php.net/array_multisort

    Also you could write tour own sorting function, here is example:

    <?php
    
    $ar1 = array ('1', '2', '3', '4', '5', '6', '7', '8');
    $ar2 = array ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');
    
    for ($j=0;$j<count($ar1)-1;$j++) {
        for ($i=$j;$i<count($ar1)-1;$i++) {
            if ($ar1[$i]<$ar1[$i+1]) {
                //  array 1
                $tmp=$ar1[$i];
                $ar1[$i]=$ar1[$i+1];
                $ar1[$i+1]=$tmp;
                //  array 2
                $tmp=$ar2[$i];
                $ar2[$i]=$ar2[$i+1];
                $ar2[$i+1]=$tmp;
            }
        }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

yet another PHP question which I am stuck on, so here is what im
Here goes a yet another SQL question about dates… I'm building a calendaring application
this is yet another .htaccess question. And I already did my literature review. Would
I have yet another question regarding the randomization of data! $gender=''; if(isset($_GET['gender'])) { $gender=$_GET['gender'];
I am about to embark upon yet another large PHP project. This time, I
Greetings all, I have yet another RegEx question. I have done hours of searching
Yes, I'm yet another person to as this annoying question... but I'm not convinced
Yet another data structure doubt. I will get straight to it. This is what
Yet another newbie with ASP.NET MVC! All I intend to do is for a
I've just added yet another 3rd-party component to my .net project that contains a

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.