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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:39:52+00:00 2026-06-07T23:39:52+00:00

When a duplicate is found in URL I want to: Take ‘score’ and add

  • 0

When a duplicate is found in URL I want to:

  1. Take ‘score’ and add it to the original
  2. Take ‘engine’ string and append it to the original
  3. Then delete the entire duplicate entry
array
  0 => 
    array
      'url' => string 'http://blahhotel.com/'
      'score' => int 1
      'engine' => string 'cheese'
  1 => 
    array
      'url' => string 'http://www.blahdvd.com/'
      'score' => int 2
      'engine' => string 'cheese'
  2 => 
    array
      'url' => string 'http://blahhotel.com/'
      'score' => int 1
      'engine' => string 'pie'
  3 => 
    array
      'url' => string 'http://dictionary.reference.com/browse/blah'
      'score' => int 2
      'engine' => string 'pie'
  4 => 
    array
      'url' => string 'http://dictionary.reference.com/browse/blah'
      'score' => int 1
      'engine' => string 'apples'

It should look like this in the end:

array
  0 => 
    array
      'url' => string 'http://blahhotel.com/'
      'score' => int 2
      'engine' => string 'cheese, pie'
  1 => 
    array
      'url' => string 'http://www.blahdvd.com/'
      'score' => int 2
      'engine' => string 'cheese'
  3 => 
    array
      'url' => string 'http://dictionary.reference.com/browse/blah'
      'score' => int 3
      'engine' => string 'pie, apples'
  • 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-07T23:39:53+00:00Added an answer on June 7, 2026 at 11:39 pm

    I believe this meets your requirements.

    Based on the desired output you provided, it appeared that you wanted to preserve the numeric indices of each entry. If you don’t actually need to preserve those numbers, you can remove the second foreach loop and the lines regarding the $indices variable, then just return $tmpList.

    function reduceEntries($entries)
    {
        $tmpList = array();
        $indices = array();
    
        foreach ($entries as $i => $entry) {
            if (isset($tmpList[$entry['url']])) {
                $tmpList[$entry['url']]['score'] += $entry['score'];
                $tmpList[$entry['url']]['engine'] .= ', ' . $entry['engine'];
            } else {
                $tmpList[$entry['url']] = $entry;
                $indices[$entry['url']] = $i;
            }
        }
    
        // rebuild final array with indices
        $finalList = array();
        foreach ($tmpList as $url => $entry) {
            $finalList[$indices[$url]] = $entry;
        }
    
        return $finalList;
    }
    

    (Here’s a working example on codepad.)

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

Sidebar

Related Questions

Possible Duplicate: Find url from string with php I found this code: but 2
Possible Duplicate: Ruby code to extract host from URL string I found this module
Possible Duplicate: keeping url parameters during pagination I want to add a parameter to
Possible Duplicate: how to remove index.php from url in codeigniter ? I want to
Possible Duplicate: Symfony - Form requested url not found I'm working on a symfony
I found that there are many frameworks that will check the duplicate class name
Possible Duplicate: SQL ORDER BY total within GROUP BY UPDATE: I've found my solution,
Possible Duplicate: Empty for loop - for(;;) I just found a strange construct in
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: What does *args and **kwargs mean? Understanding kwargs in Python I've found

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.