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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:53:21+00:00 2026-05-23T07:53:21+00:00

I would like the song titles in $Array2 to be sorted in the same

  • 0

I would like the song titles in $Array2 to be sorted in the same order of $Array1 without losing the values from $Array2. The values from $Array2 should follow the new order of each key in $Array2. I believe the current function I have provided is a solid start…

I have two arrays (please notice the differences in each):

  1. $Array1 is the user entered data.
  2. $Array2 is the data looked up on as
    external source that is SIMILAR to
    $Array1 but not EXACT.

For example…

$Array1 contains:

Array
(
    [0] => 3oh!3 - Don't Trust me
    [1] => Taylor Swift - You Belong with me
    [2] => Sean Kingston - Fire Burning
    [3] => Green Day - Know Your Enemy
    [4] => Kelly Clarkson - Gone
)

$Array2 contains:

Array
(
    [Taylor Swift - You Belong With Me] => bbbbbb
    [Sean Kingston - Fire Burning] => cccccc
    [Kelly Clarkson - Gone] => eeeeee
    [3OH!3- Don't Trust Me lyrics] => aaaaaa
    [Green Day Know Your Enemy Official] => dddddd
)

I already have a function started that I found on this website:

function sortArrayByArray(array $toSort, array $sortByValuesAsKeys)
{
    $commonKeysInOrder = array_intersect_key(array_flip($sortByValuesAsKeys), $toSort);
    $commonKeysWithValue = array_intersect_key($toSort, $commonKeysInOrder);
    $sorted = array_merge($commonKeysInOrder, $commonKeysWithValue);
    return $sorted;
}

However…

$sortArray = sortArrayByArray($Array2, $Array1);
print_r($sortArray);

$sortArray is only returning two results:

Array
(
    [Sean Kingston - Fire Burning] => cccccc
    [Kelly Clarkson - Gone] => eeeeee
)
  • 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-23T07:53:21+00:00Added an answer on May 23, 2026 at 7:53 am

    Here’s a solutions:

    <?php
    
    $array1 = array(
      0 => '3oh!3 - Don\'t Trust me',
      1 => 'Taylor Swift - You Belong with me',
      2 => 'Sean Kingston - Fire Burning',
      3 => 'Green Day - Know Your Enemy',
      4 => 'Kelly Clarkson - Gone',
    );
    
    $array2 = array(
      'Taylor Swift - You Belong With Me' => 'bbbbbb',
      'Sean Kingston - Fire Burning' => 'cccccc',
      'Kelly Clarkson - Gone' => 'eeeeee',
      '3OH!3- Don\'t Trust Me lyrics' => 'aaaaaa',
      'Green Day Know Your Enemy Official' => 'dddddd'
    );
    
    
    // Find matching song titles (case insensitive).
    $tmp = array_values(array_uintersect($array1, array_flip($array2), 'strcasecmp'));
    
    if ( ! empty($tmp) )
    {
      // Generate the array.
      $matches = array_flip(array_uintersect(array_flip($array2), $tmp, 'strcasecmp'));
    
      print_r($matches);
    }
    else
      echo 'No matches found.';
    
    ?>
    

    This will output:

    Array
    (
        [Taylor Swift - You Belong With Me] => bbbbbb
        [Sean Kingston - Fire Burning] => cccccc
        [Kelly Clarkson - Gone] => eeeeee
    )
    

    The other 2 matches are not 100% identical. As other have suggested, you could use similar_text() or other functions to determine how similar two strings are. If you’d like to do this, you can change the 'strcasecmp' in the array_uintersect call and write your own function that than uses similar_text (or other functions) to decide wether or not the values do in fact intersect or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to know what a programmer should know to become a good at
I would like to sort an array in ascending order using C/C++ . The
I have a song and a portative . I would like to color the
I would like to access the file representing the song in your ipod library,
I would like to build a program which lets lyrics of a song run
My app shows the title of a certain song and I would like to
I would like to write an interactive song. It would contain state and logic.
I would like to create an audio player using UITableView. Every song needs to
I would like to extract a channel audio from the an LPCM raw file
I would like to control the playback rate of a song while it is

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.