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
2 answers

PHP Array Unique Sort Regular not working as expected

I'm using print_r(array_unique($array, SORT_REGULAR)); on the array below but it does not work. I'm trying to filter out the redundant data. Notice that [Order] and its key value pairs are all the same. But [Transaction] and its key value pairs are…
Mike
  • 607
  • 8
  • 30
0
votes
0 answers

PHP array_unique is not returning unique values

I have an array below in which I want to get or remove duplicate values: $data = $responses; var_dump($data); result is: array(11) { [0]=> string(4) "date" [1]=> string(4) "name" [2]=> string(10) "start_time" [3]=> …
Eem Jee
  • 1,239
  • 5
  • 30
  • 64
0
votes
1 answer

array_unique/super_unique problem

I am trying to remove duplicates based on 'duplicate_check' for the following array. It seems neither array_unique nor super_unique function works. I also tried to compare two identical arrays with a loop inside a loop function, but it runs out of…
Rui Xia
  • 175
  • 4
  • 20
0
votes
2 answers

sort array using array_unique from external XML (CDATA)

I can't manage to sort an array alfabetically. It's an array with cities that I get from an external XML. The XML looks like this, and it's the node localidad I am trying to sort. 506
Helenp
  • 143
  • 2
  • 15
0
votes
1 answer

how to remove duplicate array value from multidimensional associative array?

contains the following i am trying get array_unique value from multidimensional associative array Here, i am only showing only sample array which is similar to this. $array = ['games'=>[['vollyball', 'football'], ['vollyball', 'football'],…
0
votes
1 answer

Trying to remove duplicates from JSON array with array_unique and array_values

I was following this but it still doesn't work for me: How to remove duplicate data of JSON object using PHP In my PHP file I have 3 JSON arrays: …
CHarris
  • 2,693
  • 8
  • 45
  • 71
0
votes
1 answer

how to get array unique from multidimensional array when contains associative array?

I have a multi-dimensional array that contains an associative array in every row. How to make it unique based on specified array key? I already tried some method like: $cart = array_map("unserialize", array_unique(array_map("serialize",…
Alimin
  • 2,287
  • 6
  • 19
  • 31
0
votes
1 answer

PHP - Removing duplicates from an array using array_unique()

There's been discussions about this topic before, but I haven't been able to get any of the examples from them to work in my case. Hoping this is an easy fix that may help others having similar problems. I have an html form that takes a series of 5…
Justiciar
  • 356
  • 1
  • 3
  • 20
0
votes
2 answers

Combine 2 Arrays In Foreach in PHP

I would like to combine these two foreach statements together. I've seen a few solutions around here, but nothing really works for me. This is my username list from database. $digits = [1,2,3,4]; $results = $db->table($usernames) …
Prox
  • 11
  • 4
0
votes
2 answers

PHP: Replace duplicate instances of string within array, more complex than it sounds

First time posting here after having great results searching for other answers on stackoverflow. I've hit a roadblock in an app I'm trying to build. It involves plotting a graph with JS using dynamic values pulled from a database. I'm at the point…
sagalbot
  • 118
  • 4
0
votes
1 answer

How to remove array keys from array that contain a duplicated URL?

My code is working but there is a small possibility to have duplicated $categoryurl as output, how can I keep the uniques only? I have a folder called "xml" in the webroot, I use glob() to search the /xml/ directory for the xml files. I use a loop…
jagb
  • 912
  • 11
  • 26
0
votes
0 answers

Why isn't array_unique with SORT_REGULAR working as expected?

I'm trying to get to one array that don't have duplicate values for a specific field in an array of objects. I've merged two array's of objects together and am using $unique = array_unique($merged, SORT_REGULAR) to remove any duplicate values that…
Ale
  • 437
  • 4
  • 17
0
votes
1 answer

fputcsv, multiple arrays into one row or column

I was trying to find answer but i was not successful, please help. I'm trying to populate multiple rows from data.txt by preg_match to single row or column in data.csv. It needs to be in single array because I need only unique numbers. -> or any…
Simon
  • 17
  • 1
  • 4
0
votes
1 answer

php- find duplicate and sort by array property

I have a large associative array of products. i want to check if there are duplicate products then get product with low price. I can use array_unique and array_count_values to find duplicate records, but I don't know how to handle sorting part.…
0
votes
2 answers

Remove duplicates in a slice of arrays, preserving recurring values in all other parts [PHP]

i have this kind of array: $array[] = "BRAND A|PERIOD 1|RANGE 1"; $array[] = "BRAND A|PERIOD 1|RANGE 2"; $array[] = "BRAND A|PERIOD 1|RANGE 3"; $array[] = "BRAND A|PERIOD 2|RANGE 1"; $array[] = "BRAND A|PERIOD 2|RANGE 2"; $array[] = "BRAND A|PERIOD…