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

  • Home
  • SEARCH
  • 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 8789737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:29:51+00:00 2026-06-13T22:29:51+00:00

I need to make app with will fill array with some random values, but

  • 0

I need to make app with will fill array with some random values, but if in array are duplicates my app not working correctly. So I need to write script code which will find duplicates and replace them with some other values.
Okay so for example i have an array:

<?PHP
$charset=array(123,78111,0000,123,900,134,00000,900);

function arrayDupFindAndReplace($array){

// if in array are duplicated values then -> Replace duplicates with some other numbers which ones I'm able to specify.
return $ArrayWithReplacedValues;
}
?>

So result shall be the same array with replaced duplicated values.

  • 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-13T22:29:52+00:00Added an answer on June 13, 2026 at 10:29 pm

    You can just keep track of the words that you’ve seen so far and replace as you go.

    // words we've seen so far
    $words_so_far = array();
    // for each word, check if we've encountered it so far
    //    - if not, add it to our list
    //    - if yes, replace it
    foreach($charset as $k => $word){
        if(in_array($word, $words_so_far)){
            $charset[$k] = $your_replacement_here;
        }
        else {
            $words_so_far[] = $word;
        }
    }
    

    For a somewhat-optimized solution (for cases where there are not that many duplicates), use array_count_values() (reference here) to count the number of times it shows up.

    // counts the number of words
    $word_count = array_count_values($charset);
    // words we've seen so far
    $words_so_far = array();
    // for each word, check if we've encountered it so far
    //    - if not, add it to our list
    //    - if yes, replace it
    foreach($charset as $k => $word){
        if($word_count[$word] > 1 && in_array($word, $words_so_far)){
            $charset[$k] = $your_replacement_here;
        }
        elseif($word_count[$word] > 1){
            $words_so_far[] = $word;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an app that will need to make use of Timer s, but
I need to make a photo app. Will it be possible to assign some
We need to make changes to an app that will cause all its URLS
I need to make simple CRUD web app (i'll get paid for it), but
I want to make a iPhone app but I need to now how you
I'm building a web-based chat app which will need to make an AJAX request
I have an app that will display Lotto Max numbers, I need to make
I need to make an Android app that will take data from my college
I need to make sure that our iPhone App (implemented with Monotouch) will still
I need to make an app that will run forever at the background and

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.