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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:55:45+00:00 2026-06-14T01:55:45+00:00

I want to remove some duplicate values on an array, but there is a

  • 0

I want to remove some duplicate values on an array, but there is a condition that the script has to ignore the array that contains a specific word.

Below code is adapted from PHP: in_array.

$array = array( 'STK0000100001',
                'STK0000100002',
                'STK0000100001',           //--> This should be remove
                'STK0000100001-XXXX',      //--> This should be ignored
                'STK0000100001-XXXX' );    //--> This should be ignored

$ignore_values = array('-XXXX');

if(make_unique($array, $ignore_values) > 0) {
    //ERROR HERE
}

The function to make the array unique is:

function make_unique($array, $ignore) {
    $i = 0;
    while($values = each($array))  {
        if(!in_array($values[1], $ignore)) {
            $dupes = array_keys($array, $values[1]);
            unset($dupes[0]);
            foreach($dupes as $rmv) {
                $i++;
            }            
        }
    }
    return $i;
}

I have tried to use if(!in_array(str_split($values[1]), $ignore)) ... but it just the same.

The array should become like:

STK0000100001
STK0000100002
STK0000100001-XXXX
STK0000100001-XXXX

How to do that?

  • 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-14T01:55:46+00:00Added an answer on June 14, 2026 at 1:55 am

    Try this one, just remove the print_r(); inside the function when using in production

    if(make_unique($array, $ignore_values) > 0) {
        //ERROR HERE
    }
    
    function make_unique($array, $ignore)  {
        $array_hold = $array;
        $ignore_val = array();
        $i = 0;
        foreach($array as $arr) {
            foreach($ignore as $ign) {
                if(strpos($arr, $ign)) { 
                     array_push( $ignore_val, $arr);
                     unset($array_hold[$i]);
                     break;
                }
            }
            $i++;
        }
        $unique_one = (array_unique($array_hold));
        $unique_one = array_merge($unique_one,$ignore_val);
        print_r($unique_one);
    
        return count($array) - count($unique_one);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some text that has HTML hyper-links in it. I want to remove
i have a table with some duplicate values and i want to remove them:
Possible Duplicate: PHP code to remove everything but numbers i have a loop that
I want to remove some of the dashboard menu tabs on my wordpress site
I want to remove some elements from a vector and am using remove_if algorithm
I have this matrix of size 10000 by 1. I want to remove some
I want to during the page render remove some html from the page (don't
I want to use the Oracle REGEXP_REPLACE to remove some dots from a String.
I am trying to do some string cleanup. I want to remove all the
I want to remove a specific context menu item, appears when the Mouse down(right)

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.