179 questions
0
votes
1
answer
77
views
How to stop duplicates in foreach loop with PHP? [duplicate]
I am getting a list categories names based on which tag is selected in WordPress, the code all works and returns a list of categories but I can't get the code to stop the duplicate category names.
...
0
votes
1
answer
76
views
Dividing results table in PHP into sub-tables
I am revising the question I asked before that was not clear at all.
I am very much new to PHP programming.
I have a table in postgres:
| gene_name | description|
| gene1 | kuku |
| gene1 ...
1
vote
0
answers
41
views
How do I get "explode" and "array_unique" merged
i have two tables, one separates tags by comma,
the other converts similar tags to single tags.
example:
The exploded tags table I got in the database:
<?php
foreach ($result as $row) {
...
-1
votes
1
answer
38
views
how to get 1 out of each duplicate elements on an array [duplicate]
My function store elements in an array like this:
array (
0 =>
array (
'name' => 'Roger',
'id' => '1',
),
1 =>
array (
'name' => 'David',
'id' => '2',
),...
0
votes
2
answers
66
views
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
votes
1
answer
51
views
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 ...
1
vote
2
answers
1k
views
Delete Duplicate from Two arrays and display one of the arrays in javascript
I want delete duplicate array from two arrays, but just show one of array, how I can do it ?
I want result
[1, 4]
const arr1 = [1, 2, 3, 4];
const arr2 = [2, 3, 5, 6]
function arrayUniq(arr1, arr2) {
...
-1
votes
2
answers
121
views
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 ...
0
votes
2
answers
138
views
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&...
1
vote
0
answers
170
views
Merging Multi-dimensional Array (Custom) PHP - Laravel
Merge a multi-dimensional array to the custom array as required.
Need the solution in PHP (using in Laravel-8).
Custom array is needed to make rows for creating an excel file using Spreadsheet.
This ...
-1
votes
2
answers
906
views
How do I use array_unique() with the output of MySQL query [duplicate]
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:...
0
votes
1
answer
108
views
PHP array unique does not work like expected [duplicate]
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 ...
-1
votes
1
answer
382
views
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 ...
0
votes
1
answer
56
views
array_unique() not working while I use preg_match_all php [duplicate]
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 = [...
0
votes
1
answer
134
views
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:
{
"...
1
vote
3
answers
103
views
PHP Array_unique [duplicate]
Is it possible to remove sub arrays, if the array item at position 0 of that sub array matches subsequent items?
For example;
Array ( [0] => Array ( [0] => 1234 [1] => XX000 )
[1] =&...
0
votes
0
answers
176
views
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] ...
1
vote
3
answers
212
views
Why is my filter method not removing some elements that should be removed?
I am trying to create a method called filer_out! that takes in an array and a proc, and returns the same array but with every element that returns true when it is run through the proc, with the caveat ...
0
votes
3
answers
79
views
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 => '...
1
vote
2
answers
78
views
Find duplicates in a multidimensional array and echo out them
I want to find duplicates in a multidimensional array and then echo out which one who has duplicates and which not. I've tried this code.
$teams = array
(
"grupp_A" => array('Arsenal','...
6
votes
2
answers
568
views
array_unique with SORT_NUMBERIC behaviour
I've stumbled upon something weird and I don't understand why it works that way.
I have an array of numbers, they are all unique:
$array = [
98602142989816970,
98602142989816971,
...
0
votes
1
answer
34
views
Sort Array in Array
I have following array result:
Example:
[
{
id: "1",
league: {
name: "World Club Friendlies",
team: "Simple 1 & Simple 2"
}
},
...
0
votes
1
answer
71
views
PHP remove duplicate array values [duplicate]
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
[...
-1
votes
2
answers
210
views
Distinct values using PHP [closed]
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 ...
0
votes
1
answer
52
views
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' =>...
1
vote
1
answer
125
views
Invalid JSON format in using array_unique function [duplicate]
I have removed the duplicate items for the following array, by writing:
$outcome['id'] = array_unique($outcome['id'], SORT_REGULAR);
but I'm getting undesirable JSON output
"id": {
"0"...
-1
votes
1
answer
351
views
Counting a unique value from an Array set [closed]
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 ...
2
votes
3
answers
311
views
What alternative of code that work in PHP7 in PHP5
I have a PHP code which runs on PHP7 but not in PHP 5, which PHP version in my server, that is my code:
Array (
[0] => stdClass Object (
[userId] => 15
[name] => name0
...
0
votes
1
answer
106
views
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 ...
-1
votes
4
answers
1k
views
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] => ...
0
votes
2
answers
1k
views
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","...
0
votes
2
answers
250
views
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 [
...
0
votes
2
answers
618
views
PHP Array Unique Sort Regular not working as expected
I'm using print_r(array_unique($array, SORT_REGULAR)); on the array below but it does not work.
I'm trying to filter out the redundant data.
Notice that [Order] and its key value pairs are all the ...
0
votes
0
answers
41
views
PHP array_unique is not returning unique values [duplicate]
I have an array below in which I want to get or remove duplicate values:
$data = $responses;
var_dump($data);
result is:
array(11) {
[0]=>
string(4) "date"
[1]=>
string(4) "name"
...
1
vote
0
answers
186
views
What change does array_unique() make when migrating to PHP 7.2?
Here is the description of array_unique() in PHP 7.2:
If sort_flags is SORT_STRING, formerly array has been copied and
non-unique elements have been removed (without packing the array
afterwards)...
0
votes
2
answers
67
views
sort array using array_unique from external XML (CDATA)
I can't manage to sort an array alfabetically.
It's an array with cities that I get from an external XML.
The XML looks like this, and it's the node localidad I am trying to sort.
<parada>
...
0
votes
1
answer
312
views
how to remove duplicate array value from multidimensional associative array?
contains the following i am trying get array_unique value from multidimensional associative array
Here, i am only showing only sample array which is similar to this.
$array = ['games'=>[['...
0
votes
1
answer
2k
views
Trying to remove duplicates from JSON array with array_unique and array_values
I was following this but it still doesn't work for me: How to remove duplicate data of JSON object using PHP
In my PHP file I have 3 JSON arrays:
{"results":[{"cat_id":2,"cat_name":"veterinarian"...
0
votes
1
answer
1k
views
how to get array unique from multidimensional array when contains associative array? [duplicate]
I have a multi-dimensional array that contains an associative array in every row. How to make it unique based on specified array key?
I already tried some method like:
$cart = array_map("...
-4
votes
1
answer
348
views
FOREACH LOOP RETURNING DOUBLE RESULTS [closed]
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:
<?php
while($row=$stmt_header->fetch(...
0
votes
1
answer
83
views
PHP - Removing duplicates from an array using array_unique()
There's been discussions about this topic before, but I haven't been able to get any of the examples from them to work in my case. Hoping this is an easy fix that may help others having similar ...
-1
votes
1
answer
65
views
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 ...
0
votes
2
answers
1k
views
Combine 2 Arrays In Foreach in PHP
I would like to combine these two foreach statements together. I've seen a few solutions around here, but nothing really works for me.
This is my username list from database.
$digits = [1,2,3,4];
$...
0
votes
1
answer
96
views
How to remove array keys from array that contain a duplicated URL?
My code is working but there is a small possibility to have duplicated $categoryurl as output, how can I keep the uniques only?
I have a folder called "xml" in the webroot, I use glob() to search the ...
1
vote
2
answers
3k
views
PHP - Array unique only using specific values
I have a PHP array that looks like this...
Array
(
[0] => Array
(
[id] => 1
[value] => 111
[date] => 'today'
)
[1] => Array
(
[id] =>...
1
vote
3
answers
132
views
Duplicate remove from foreach
I want to remove duplicates image. How to use array_unique? This is what I have tried:
$text = 'text image.jpg flower.jpg txt image.jpg';
$pattern = '/[\w\-]+\.(jpg|png|gif|jpeg)/';
$result = ...
0
votes
0
answers
391
views
Why isn't array_unique with SORT_REGULAR working as expected?
I'm trying to get to one array that don't have duplicate values for a specific field in an array of objects. I've merged two array's of objects together and am using $unique = array_unique($merged, ...
0
votes
2
answers
576
views
Get unique ids from a txt file and append them to a csv file
I'm trying to populate multiple rows from data.txt by preg_match_all() to single row or column in data.csv. It needs to be in single array because I need only unique numbers (or any other option the ...
1
vote
1
answer
36
views
Select unique arrays from multidimensional array with exception of date
I have a multidimensional array like this
Array
(
[0] => Array
(
[name] => test
[c1] => flower
[c2] => fruit
[date] => 2017-...
1
vote
3
answers
230
views
PHP - Delete all duplicates in array
How can I delete duplicates from multiple arrays?
pinky and cocos are double in my array. All words which are double, must be removed. If those are removed, I will put these words in my select.
I ...