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

foreach array_unique not working

I have this code: @foreach($files['folders'] as $file) @foreach(array_unique($file['file_name']) as $names) {{$names}} @endforeach @endforeach Returns null. I want array $file display only DISTINCT $file['file_name'].
0
votes
3 answers

PHP, Remove duplicate and blank line

I get values from the textarea as follows: 2342 de20343 23094 zz900 234432 zz900 2342 I want to find duplicates (eg: "zz900" and "2342") and delete them. In addition, blank lines must be removed. Is there a single function that will do this?
od_
  • 183
  • 3
  • 16
0
votes
3 answers

Remove duplicate using array_unique

Hi I'm trying to loop through a list of tags using wordpress. The list of tags is generated through another plugin. at present this is the code I have
Chris Martin
  • 33
  • 2
  • 10
0
votes
2 answers

removing array duplicates from associative array

So i have: Array ( [animals] => Array ( [0] => horse [1] => dog [2] => dog ) [team] => Array ( [0] => cubs [1] => reds [2] => cubs …
Hard Fitness
  • 452
  • 3
  • 9
  • 24
0
votes
1 answer

Delete double values using php inside an array (wp-query and ACF)

I'm using advanced custom fields on my website with a select field (type_evenement) with 5 possible values (val_1, val_2, val_3, val_4, val_5) I'm using also a wp query on a custom template page to display posts from a category, all posts uses the…
mmdwc
  • 1,095
  • 6
  • 27
  • 53
0
votes
0 answers

Trying to share Gulp project with a friend

I have made a gulp project and I am trying to share it with a friend. Its a simple css grid with gulp tasks integrated. You can download the package here: https://www.dropbox.com/s/od1dsh75tegbq24/projectfolder.zip?dl=1 When you unzip the package…
Jabba Da Hoot
  • 794
  • 2
  • 7
  • 16
0
votes
2 answers

How to array_unique dimensional arrays

How to array_unique dimensional arrays I have array below : Input Array [0] => Array ( [staff_id] => 1 [service_id] => 1 [avatar_url] => gallery-1.png [full_name] => Germaine [price] => 0.00 ) [1] =>…
0
votes
2 answers

Displaying number of instances of each array value

$myArray = array(2, 7, 4, 2, 5, 7, 6, 7); $uniques = array_unique($myArray); Along with displaying each value in the array only once, how would I ALSO display (in the foreach loop below) the number of times each value is populated in the array. IE…
Dean Olsen
  • 131
  • 4
  • 13
0
votes
5 answers

Php array unique subarray based on a value

I am in a situation to make an array unique by the subarray index.Please refer this code and help me to solve this. $user=Array( [1]=>Array( username => Sujith, email=>someone@example.com, …
sujithayur
  • 376
  • 3
  • 13
0
votes
1 answer

PHP print out only unique values from array

I'm hoping someone can help me with a problem I am having returning only unique values from an array. I am pulling data from the 500px API of photographs that I have favourited. From this array I would like to pull out the category IDs of the…
Stuart Brown
  • 977
  • 2
  • 22
  • 47
0
votes
1 answer

Remove duplicates using array_unique and printing the result

I've been searching and trying for hours, I want to look for duplicates in my variables which print numbers and then eliminate the duplicates leaving just original numbers. Here is what I've been trying: $priceminpps =…
0
votes
1 answer

array_unique wrongly discarding values

I'm trying to use array_unique to discard of repeated values. Array ( [0] => Array ( [book_id] => 1203910329 [author] => Gauci, Joe [description] => Paperback. Very Good. [isbn] =>…
mk_89
  • 2,692
  • 7
  • 44
  • 62
0
votes
2 answers

Remove duplicates of wp_user foreach with array_unique - rendering error?

Combining taxonomies and user roles, I am listing all terms of tax "dog", and for each term "dog", a list of all "colors" that are linked to a user profile. EXAMPLE: User 1 has meta "Dog: Golden Retriever" and "Color: Yellow" stored with profile. …
Caroline
  • 104
  • 1
  • 10
0
votes
2 answers

PHP unset Not Working as expected

I am simply trying to remove all of the Array objects that have 'visible' set to…
ChristopherStrydom
  • 7,338
  • 5
  • 21
  • 34
0
votes
0 answers

array_unique a specific array within a multi-dimensional array

I have an array with multiple arrays within that array and what I want to do is to have the ability to run an array_unique on one of the arrays within my master array, but for every item that array_unique removes, I need it to remove that item from…