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

How to detect duplicate values in multidimensional associative array?

I have an associative multidimensional array: Array ( [0] => Array ( [customer_name] => John Dow [customer_email] => john@example.com [customer_mobile] => 1236547895 [birth_date] =>…
Devendra Singh
  • 99
  • 1
  • 2
  • 13
0
votes
1 answer

php array_unique returns empty array depending on server

I have a line of code that has worked on my local develop machine but does not work (as expected) on another machine. Here is my debugging of the call to array_unique: debug("Parameter array size: ".sizeof($parameters)); debug("Sorted array size:…
youcantryreachingme
  • 1,065
  • 11
  • 17
0
votes
5 answers

Can array_unique be used for multi dimensional arrays

i just wanted to know whether array_unique be used for multi dimensional arrays
Anish Joseph
  • 1,026
  • 3
  • 10
  • 24
0
votes
1 answer

How to have value follow each other in PHP?

How do I find the values in an array that matches another array in order? Here is my code that gives me the $Array4 which does not correspond to the expected result (given below):
Marie
  • 13
  • 4
0
votes
0 answers

How to get Unique value of subarray?

Actually, I am getting array and subarray. I want to get the unique values from the subarray. I tried many things but it is not working for me. Here is the array value of mine Array ( [title] => Array ( [0] => Cake…
jayant rawat
  • 305
  • 4
  • 19
0
votes
3 answers

Merge array to output an array with only unique values

I have 2 arrays that I need merged to create another array with unique values. Array 2 is the entire list of possible file versions, and Array 1 is the current versions of the files. If items from Array 1 and Array 2 have the same id value, I want…
AlexB
  • 2,164
  • 6
  • 27
  • 61
0
votes
2 answers

php array_unique method "puts key into array"

Im going to parse json to my array by unique values. But here is some problem about array_unique function. For example: $contract_types = [ "Asset Sale and Purchase Agreement", "Asset Sale and Purchase Agreement", "Concession Agreement" ]; and…
0
votes
1 answer

How can I remove duplicate subarrays from my multidimensional array?

I have an array: array:3 [▼ 0 => array:1 [▼ "name" => "test#4" ] 1 => array:1 [▼ "name" => "C" ] 2 => array:1 [▼ "name" => "C" ] ] I want to get only the unique values: array:2 [▼ 0 => array:1 [▼ "name" => "test#4" …
code-8
  • 54,650
  • 106
  • 352
  • 604
0
votes
4 answers

PHP - Using implode, explode, and array_unique to autopopulate a dropdown menu from two SQL columns of comma-separated keywords

I have an SQL database with a "category" keyword (only one allowed) and "issues" keywords (multiple comma-separated words). I am trying to make a auto-populating drop-down keyword select menu by selecting all the keywords from the "category" and…
teame
  • 1
  • 6
0
votes
3 answers

Remove duplicates from PHP array (array_unique)

I am getting a specific field from 4 different tables.
Datacrawler
  • 2,780
  • 8
  • 46
  • 100
0
votes
2 answers

Trouble with array_unique

print_r($tokens); $tokens = array_unique($tokens); print_r($tokens); Gives the following output: Array ( [0] => Array ( [Class_ID] => 32709 ) [1] => Array ( [Class_ID] => 34682 ) …
Ben G
  • 26,091
  • 34
  • 103
  • 170
0
votes
1 answer

Removing array elements that contain other array elements

I have an array of Google location entities taken from Geocoding API ($glocs). Sometimes one element of the array partially repeats in another ("Federation of Bosnia and Herzegovina, Bosnia and Herzegovina", for instance). As I output them in the…
Walt
  • 11
  • 2
0
votes
2 answers

PHP - array_unique not changing output

I have an array $tmp: $a = array(0 => 49, 1 => 49, 2 => 49); after using array_unique($tmp) I'm getting this output: Array ( [0] => 49 [1] => 49 [2] => 49 ) and I want to get Array ( [0] => 49 ) What am I doing wrong? Im new in…
gkopowski
  • 107
  • 1
  • 10
0
votes
1 answer

Why is php array_unique($array); producing duplicate values

I have a php function I'm trying to make efficient as possible, but there are redundancies I cannot get rid of. So I need some help. Here's the actual code if you would like to take a look function array_tags( $classes, $item, $args ){ if (…
Chris Haugen
  • 825
  • 1
  • 7
  • 22
0
votes
1 answer

How to extract unique values from this multidimensional array?

How to extract unique values from this array. I've tried another suggestion... $input = array_map("unserialize", array_unique(array_map("serialize", $input))); However because of the unix timestamp it wont work. Im looking to extract only the…
succeed
  • 834
  • 1
  • 11
  • 28