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
1
vote
1 answer

Array unique multidimensional on one column

I have a big array like this this one (only 5 entries here) Array ( [1] => Array ( [last_token] => atokenforexample [idmembre] => 31800 [key] => 821fbe3f4623649562f75a3de132c908 …
1
vote
1 answer

array_unique not working with xml?

it's my first time using array_unique and I'm not sure if I'm doing something wrong. I have the following code: array_unique($items); print_r($items); foreach ($items as $item) { echo "$item
"; } print_r is returning: Array ( [0] =>…
Esteban89
  • 671
  • 1
  • 8
  • 20
1
vote
3 answers

Wordpress Get unique custom field values in a list

I have a whole list of directors but would like to display only their unique names not duplicates. Something that looks like director A, Director B, Director C,... NOT director A, Director A, Director B, Director C, Director C,... I try to do this…
Phil
  • 561
  • 2
  • 16
  • 29
1
vote
1 answer

PHP array_unique do not work for my array

i have a function that return an array like this: Array ( [0] => Array ( [0] => #fff4f4; [1] => fff4f4 ) [1] => Array ( [0] => #ffffea; [1] => ffffea ) [2] => Array ( [0] => #ffc; …
AleMal
  • 1,977
  • 6
  • 24
  • 49
1
vote
0 answers

PHP array_unique not behaving as expected

I have a little PHP script I am running. It basically puts the content of an XML file and assigns it to a variable. I then create an array containing all the XML tags and values I want to use, using the parse array function from…
MyGodAL3X
  • 11
  • 1
1
vote
3 answers

javascript array duplicate in another array

Suppose i have this array in javascript ar = ['C241C12A-45FD-40FF-B26E-B879107E584D||20', 'AB1BB99D-4396-415A-A5D8-1BEF3E0149CE||33', 'ADE54113-53D1-4F26-A01C-48EBE37E3CE8||85', 'DB500FD1-5988-4202-A4AA-727AC29AC67A||85', …
coolguy
  • 7,866
  • 9
  • 45
  • 71
1
vote
1 answer

array_unique ignores 0

I have an array of floats. When I use array_unique, if I have a 0 value, it's left out of the result. Is this correct, or is there a way around this? What's the proper syntax to make it include 0s. Thanks in advance!
user1382306
1
vote
4 answers

remove duplicate keys from a multidimensionnal array

I have a multidimensionnal array of objects: 0 => array 32281 => object ... 105145 => object ... 165656 => object ... 194124 => object ... 195397 => object ... 205859 => object ... 1 => array …
user1705785
  • 53
  • 1
  • 6
1
vote
1 answer

PHP array/array_unique confusion

I create an array of image URLs: $matches = array(); preg_match_all('#(http://[^\s]*?\.jpg)#i',$html, $matches); $matches2 = array_unique($matches); // get unique echo "there are ".count($matches2)." items!"; print_r($matches); The count shows…
StudioTime
  • 22,603
  • 38
  • 120
  • 207
1
vote
4 answers

removing duplicates from an array in php

I want to remove duplicate elements from an array in php. Following is the structure of the array Array ( [0] => Array ( [0] => xllga@hotmail.com [1] => bounce@abc.com [2] =>…
Deepak
  • 229
  • 1
  • 4
  • 15
0
votes
2 answers

Writing a file within for loops using php

I am having a lot of problem while writing a file within foreach loop. It either writes the line which is at the end in the array or is it at the start of the array. For Example: A file contains such…
Nida Zubair
  • 23
  • 2
  • 5
0
votes
3 answers

Replace duplicates in a text file with PHP?

I have text files that have list of thousands of names like this DallasWebJobs DallasWebJobs DallasWebJobs php_gigs brotherjudkins goldbergwb SanDiegoWebJobs brinteractive muracms browan85 php_gigs php_gigs php_gigs php_gigs 1 name per line, 1 file…
CodeDevelopr
  • 1,267
  • 3
  • 17
  • 30
0
votes
1 answer

How to display result using only arrays, without MySQL database

I have script which fetches remote XML file and displays table with product data. data has following format: ID, name, price, months. +++++++++++++++++++ 1, Name1, $24, 12 2, Name2, $11, 24 2, Name2, $10, 36 3, Name3, $16, 12 2, …
Besik
  • 43
  • 7
0
votes
2 answers

Remove Duplicate Nested Arrays From Multidimenssional Array By Nested Array Key

I am trying to create an array where I need to filter with a certain key (fileid) so that it returns only unique keys for parent array. Here is what I have.. Array ( [ABCD] => Array ( [0] => Array ( …
Abhik
  • 664
  • 3
  • 22
  • 40
0
votes
1 answer

php Keeping only 1 date occurence in multi-dimensional array

I have this array with certain brand_ids, within these brands I have an array of dates in which a sale occured but these are based on the products in sale so they may appear multiple times on the same brand_id; This is my array: array:5 [▼ 2 =>…