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

How can I find all results in a PHP array, merge values, and then merge into another array

Using PHP, I have an array like this: Array 1 [ {epid: "123", hash: "xxxxxx"}, {epid: "456", hash: "xxxxxx"}, {epid: "789", hash: "xxxxxx"}, {epid: "123", hash: "xxxxxx"}, {epid: "123", hash: "xxxxxx"}, ] Then, I have a second array like…
Keith Petrillo
  • 125
  • 2
  • 10
0
votes
1 answer

PHP array unique does not work like expected

I have a problem with array_unique() in PHP. Here is my code: $filterGroupsArray = ['', 'a', 'a', 'b']; print_r($filterGroupsArray); array_unique($filterGroupsArray); print_r($filterGroupsArray); The output is Array ( [0] => [1] => a [2] => a [3]…
broxyl
  • 37
  • 6
0
votes
1 answer

array_unique() not working while I use preg_match_all php

my code is : $a = <<<'EOD' function makeItBIG($a_lot_of_names) { foreach($a_lot_of_names as $the_simpsons) { $BIG[] = strtoupper($the_simpsons); } return $BIG; } $a_lot_of_names = ['Homer', 'Marge', 'Bart', 'Maggy',…
RsF
  • 21
  • 1
  • 6
0
votes
1 answer

Merge PHP arrays to create named keys and unique values

I have an object which contains 3 arrays, any of which may be empty, it is feasible all three can be empty, so I need to handle that requirement too. Here's an example of the object: { "lang_read": [], "lang_write": ["es", "ca", "zh", "en",…
0
votes
0 answers

How to remove duplicate rows from stdClass codeigniter

stdClass Object ( [id] => 132 [slug] => test [parent_id] => 15 ) stdClass Object ( [id] => 132 [slug] => test [parent_id] => 15 ) I used the array_unique function to delete…
ebrahim
  • 87
  • 1
  • 10
0
votes
3 answers

Get Unique Values from Array 2 Compared to Array 1 and Output in Array 3

I have 2 arrays and need to find the unique values in the second array that are not in the first array and output those to a third array. Array 1 $array1 = array( 0 => 'value12', 1 => 'value34', 2 => 'value56', 3 => 'value79', ); Array…
Mike
  • 607
  • 8
  • 30
0
votes
1 answer

How do i remove duplicate links from a page except first

I have a problem with some contents, which have the same link again and again, so i want to remove all duplicate links except a single, have anyone idea how to do this???? here is my code which remove all links function anchor_remover($page) { …
Bheem
  • 307
  • 2
  • 8
  • 24
0
votes
1 answer

Sort Array in Array

I have following array result: Example: [ { id: "1", league: { name: "World Club Friendlies", team: "Simple 1 & Simple 2" } }, { id: "2", league: { …
0
votes
1 answer

PHP remove duplicate array values

Let me explain my situation, i got myself a multidimensional array.. Down below is the print_r of my array. Array ( [0] => Array ( [firstname] => Tinga [lastname] => [email] =>…
Izzy
  • 61
  • 5
0
votes
2 answers

Distinct values using PHP

I want to get only the distinct values from $pjt. I have tried the below code: $unique_pjtdata = array_unique($pjt); foreach($unique_pjtdata as $val) { echo $val; } I am getting an HTTP Error 500 after trying this code.
FRECEENA FRANCIS
  • 181
  • 2
  • 13
0
votes
1 answer

Convert PHP multidimensional array so that the values become keys, and and other values become arrays for each key

I have: ['countryCode' => 11, 'postalCode' => 12345], ['countryCode' => 11, 'postalCode' => 12346], ['countryCode' => 11, 'postalCode' => 12347], ['countryCode' => 11, 'postalCode' => 12348], ['countryCode' => 11, 'postalCode' =>…
0
votes
0 answers

String to Array using Array_unique and echo results

UPDATE After playing around with the code I can display the string as an array and print it which is displaying the following Array ( [0] => anagram ) Array ( [0] => anagram ) Array ( [0] => anagram ) Array ( [0] => anagram ) Array ( [0] => anagram…
Mal
  • 5
  • 6
0
votes
1 answer

Looping through files with foreach(); need to remove duplicate results before printing

I'm writing some code to automate fontfaceobserver.js. For each font file in a directory I need to get the font family name so I can print it in the javascript. Some of the fonts share the same family name followed by a style name, e.g,…
0
votes
2 answers

foreach loop output first value only in loop

Why foreach loop printing only the first value from the array? $Jdata_cate = '[{"category_id":"103","name":"Martin","parent_id":0},{"category_id":"10","name":"Juan","parent_id":0},{"category_id":"9","name":"Kasi","parent_id":0}]'; $J_Min =…
0
votes
2 answers

Removing entire array elements if an element in a sub array already exists in another element

I have a multidimensional array, consisting of products. Each sub-array has a product type. The productType is is in an array inside the Product array, such that; 0 => product [ productType [ id: 2 ] ] 1 => product [ productType [ id:…