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

Why array_unique doesn't work with explode()?

So I have db table>"schools" and a column in this table named "metro". In "metro" i have strings like that "Station Name 1, Station Name 2, Station-Name 5" I'm doing now a search form with select metro stations, so my code look like this:
-1
votes
1 answer

how to get 1 out of each duplicate elements on an array

My function store elements in an array like this: array ( 0 => array ( 'name' => 'Roger', 'id' => '1', ), 1 => array ( 'name' => 'David', 'id' => '2', ), 2 => array ( 'name' => 'David', 'id' => '2', …
-1
votes
2 answers

PHP Easier way to get unique in array of objects

I have been racking my head trying to think if there is a simpler method to grabbing the unique objects out of an array, but can't find any documentation or confirmation that anything exists that will do what I am asking. I have an API returning the…
Zak
  • 6,976
  • 2
  • 26
  • 48
-1
votes
2 answers

How do I use array_unique() with the output of MySQL query

I have a fairly complex MySQL call that results in simple output something like this; name timestamp comm1 comm2 counter Bill 2021-04-18 19:31:00 data data 1 Bill 2021-04-18 19:32:00 data data 2 Bill 2021-04-18 19:33:00 …
Keith D Kaiser
  • 1,016
  • 2
  • 14
  • 31
-1
votes
1 answer

what should I use instead of array_unique in php?

I am getting duplicate data in an array and that data is storing in my DB. I am using array_unique to refine the duplicate data but it is not working. Please tell me is there any other way to make data unique and store in DB this way. if…
-1
votes
1 answer

Counting a unique value from an Array set

I have an array that repeats the same values twice. I am unable to count the total of the unique values. I mean the phone number is unique and when the same phone number appears twice it should be counted as one. I have tried by using the method…
-1
votes
4 answers

Removing Duplicates and Merging Multidimensional Array

Need to merge the Multidimensional array into single array, thereby, eleminating the duplicate values taking key as username and values as their user friends details Array ( [Nishanth] => Array ( [0] => Array …
Nɪsʜᴀɴᴛʜ ॐ
  • 2,756
  • 4
  • 33
  • 57
-1
votes
1 answer

retrieve unique values or arrays from data in php

I'm building out a filtering function that loops through provided data to generate select field options based on a declared array key. I can get my function to output the expected unique results when the key value is a string, however when I set the…
Matt
  • 806
  • 3
  • 12
  • 32
-1
votes
4 answers

how to create unique array from array

Array [0] => Array ( [a1] => 12 [v1] => 3100.00 [v2] => 186.00 [v3] => 186.00 ) [1] => Array ( [a1] => 12 [v1] => 1200.00 [v2] => 72.00 [v3] => 72.00 ) i want to…
-1
votes
6 answers

php array unique for urls

I need to identify unique urls from an array. All of the following variants should count as equal: http://google.com https://google.com http://www.google.com https://www.google.com www.google.com google.com I have the following solution: public…
Chris
  • 13,100
  • 23
  • 79
  • 162
-1
votes
1 answer

PHP Array Unique

I believe my issue is fairly basic and simple, but I think I am not getting through it.I have a PHP array which has been dynamically populated with data from the database $PInvoicesList=array(); $SelectPInvoicesList ="SELECT * FROM…
UmarAbbasKhan
  • 91
  • 1
  • 12
-1
votes
1 answer

array_unique - php - codeigniter

$skillsarray = ["php","java","ios","php","php","php","php","java","java","ios"]; $cityarray = ["Chennai","Theni","Theni","Mumbai","Chennai","Theni","Chennai","Hyderabad","Theni","Madurai"]; If I used array_unique for $skillsarray, getting result…
Muhilan
  • 51
  • 1
  • 9
-2
votes
2 answers

array unique not working fine on a tag string

I have been battling on how to display distinct tag that I stored in database. In my database I have saved some tags, when I tried displaying it back I used array unique but it didn't work. see below example database item |…
peter Bou
  • 39
  • 1
  • 7
-2
votes
1 answer

array_unique returns nothing at all

i have an array called res_rooms returning this using print_r($res_rooms); Array ( [0] => 80 [1] => 50 [2] => 80 [3] => 50 [4] => 80 [5] => 50 [6] => 80 [7] => 50 [8] => 80 [9] => 50 [10] => 80 …
jq beginner
  • 1,010
  • 3
  • 21
  • 41
-4
votes
1 answer

FOREACH LOOP RETURNING DOUBLE RESULTS

I am outputting results from a table with multiple columns. So I used a foreach loop to loop through but it is returning double results. Here is my code: fetch(PDO::FETCH_BOTH)) { ?> …
1 2 3
11
12