Questions tagged [array-unique]

PHP's array_unique() function accepts a single array and returns a new array with all duplicate values removed

PHP's array_unique() function accepts a single array and returns a new array with all duplicate values removed. The second optional parameter is used to modify the ordering of the values in the returned array

Example:

$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);

Result:

Array
(
    [a] => green
    [0] => red
    [1] => blue
)
180 questions
0
votes
4 answers

Should I use asort after array_unique if the array was asorted before?

$arr = asort($arr); //some magic code goes here, $arr is not changed $arr = array_unique($arr); Should I use asort again to be sure $arr is asorted? My tests show that no, I don't. But I'm not sure for 100% if array_unique actually removes the…
Haradzieniec
  • 9,086
  • 31
  • 117
  • 212
0
votes
3 answers

array_unique not giving expected result

I'm trying to grab all the unique values of an array. $Arr_TitleID = "92 1 92 38 1 6 1"; echo "Arr_TitleID: " . $Arr_TitleID; $TitleID_Explode = explode(" ", $Arr_TitleID); $BigTitleID_Explode = array_unique($TitleID_Explode); $CTID_count =…
Alan N
  • 181
  • 2
  • 8
0
votes
1 answer

better function to use - array_unique or array_search

Which function should be used, array_unique or array_search, while comparing speed. I have an array that is full of duplicate entries, now I have 2 options to make my array unique. I am confused, which function should I use for better performance?
Guman Thakur
  • 27
  • 1
  • 4
0
votes
1 answer

multidimensional array conversion is not working

Very frustrating moment and could not figure out and finally decided to move and ask to Geeks about solution. Okay, Here is the problem. I have below array and need to convert it by replacing repeating records from array and merge is as shown…
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
0
votes
2 answers

Return Unique Value from Chunked Array

I have a calendar script that outputs to a text file. I'm opening the text file, reading it into an array and then outputting the results. The text file contains: 7/9/2013-7/13/2013 Hot Stuff By Robert More. Yes, folks, it's all platform shoes,…
user235621
0
votes
2 answers

how to take value of 'while' to include array unique

table: fungi | fruit | country fungi-a Aple, Orange, Grape, Japan, America, China, Australia, fungi-b Aple, Watermelon, Grape, Korea, America, China, fungi-c Aple, Watermelon, Orange, Korea,…
0
votes
1 answer

Return unique values from a column with multiple values per field

I have a database table with a column where multiple strings are stored in each field, separated by a ; I need to get a list of all unique values in that column. I know there has to be an easier way to do this, but I can't find my answer anywhere.…
0
votes
2 answers

How to combine two associative arrays, remove duplicate values while keeping the keys, and the sort alphabetical

So I have two associative arrays with family members and names. Each array have the same index key, but different values. I need to combine the two arrays, remove duplicate values, not duplicate keys, then sort it alphabetical. So far I have Array1…
user1781482
  • 623
  • 3
  • 15
  • 24
0
votes
3 answers

simplexml_load_file remove duplicate keys

I'm loading an XML file, which happens to have duplicate items in it. I wish to remove those, but trying so throws me an error: Message: It is not yet possible to assign complex types to properties The return of the xml function is off course an…
Gerard Nijboer
  • 502
  • 1
  • 7
  • 18
0
votes
2 answers

Why isn't array_unique returning me a list of unique items?

I am trying to scrape all the urls on the home page on my client's site so I can migrate it to wordpress. The problem is I can't seem to arrive at a de-duplicated list of urls. Here's the code: $html =…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
0
votes
1 answer

PHP array_ merge array_unique lower/upper case

Right now , I have a return function : return array_unique(array_merge( $sizes, $custom_sizes )); My problem is that a certain key can be lower case in one, and upper case in other . For example , I can get "Thumbnails" in $sizes and "thumbnails"…
Obmerk Kronen
  • 15,619
  • 16
  • 66
  • 105
0
votes
2 answers

php: using google csv, remove duplicate values populated in column

I am a newbie to php and have been searching tirelessly for a solution to this problem (i'll bet its a super simple solve too *sigh). I am importing a .csv feed from a google doc. It is pulling in 2 columns, one for "name" and the other "location".…
christa
  • 1
  • 1
0
votes
1 answer

Assoc Array manipulation - array("value1", "value2") to array(array("keyname" => "value1"), array("keyname" => "value2"))

What I'm doing is taking a basic array, with default numeric keys: $basic_array = array("value1", "value2", "value3") and I want to merge that array with an associative array set up like: $associative_array = array(array("filename" => "value4"),…
Josh L
  • 39
  • 6
0
votes
1 answer

array_unique not working with filename strings imported from text file

THE PROCESS: User checks checkboxes to share files with customer accounts Checkbox values are compared against an array stored in a txt file from the customers folder The arrays are compared by being merged into one array using array_merge() The…
Bryan
  • 3
  • 1
1 2 3
11
12