Questions tagged [array-difference]

Used for questions concerning the difference between arrays. For example, where elements in two arrays differ from each other, or subtracting the content of one array from another. Since the tag can be broadly applied to any programming language that supports arrays, use use one or more additional tags in order to help identify the specific language the question relates.

An array is a data structure that encompasses a group of elements. When working with arrays there can be a requirement to determine the difference between two or more arrays, and this tag is for questions relating specifically to finding that difference.

The difference between arrays can be determined in a number of ways, including finding where elements within the array differ, and can include operations such as subtracting the contents of one array from another to produce an outcome.

273 questions
2
votes
1 answer

How to compare arrays with different sizes

I want to compare 2 arrays, except the two arrays may sometimes be of different sizes. For example, I have a form and I receive the values with this: // The post send more values than other array: // name , email , password, phone , address //…
2
votes
4 answers

Create a 'results' array based on comparison of two two-dimensional arrays?

I have two two-dimensional arrays I'd liked to compare to one another: $array1 Array ( [0] => Array ( [A] => GB [B] => Harry [C] => British Army [D] => Eton College [E] =>…
Elijah Paul
  • 281
  • 4
  • 22
2
votes
1 answer

array_diff gives Array to String conversion error in drupal

I am experiencing a weird error from an array_diff statement. The statement is: $query = array_diff($params, array('f' => array())); and the var_dump of the $params is array(1) { ["f"]=> array(0) { } } This happens in a drupal module called…
lloydh
  • 395
  • 2
  • 5
  • 16
2
votes
5 answers

array_diff() based on one column between two arrays with associative rows

I have two multidimensional arrays which are indexed arrays of associative rows. $array1 = array( array('name' => 'foo', 'id' => 12), array('name' => 'bar', 'id' => 34), array('name' => 'boo', 'id' => 56), ); $array2 = array( …
2
votes
3 answers

Compare two arrays of objects by references?

I'm trying to compute difference of two arrays of objects with array_udiff(). My object structure is complicated and I can not rely on quantitative properties, because those properties of objects in both arrays may have same values, but they are…
BlitZ
  • 12,038
  • 3
  • 49
  • 68
2
votes
3 answers

Comparing Array with multidimensional array

I have 2 arrays : labels = ["water", "sever", "electricity"]; services = [0:[0:"1",1:"sever"], 1:[0:"3",1:"park"], 3:[0:"4",1:"gas"]]; I want to check if ANY of labels value is in services or not (True or False). What is the best way to archive…
apaleja
  • 395
  • 4
  • 8
  • 21
2
votes
1 answer

PHP Multidimensional Arrays - Remove Duplicates

if anyone could please help me here I would be eternally grateful as I've spent about 2 full days now trying to get this to work. I want to take two multidimensional arrays and compare them, then remove any duplicate records. The scenario is: The…
SigmaSteve
  • 664
  • 6
  • 25
2
votes
0 answers

Decode when json is encoded at different depths

I am trying to use array_diff in order to see what changes had been made to an account. The account data is encoded as json files. The problem is that when I decode the json, I get a multidimensional array. As specified in the manual: Note: Please…
Cornelia Secelean
  • 403
  • 1
  • 4
  • 14
2
votes
1 answer

Array.toString data handling in Java

I'm confused the way data has been manipulated here in this case, thought will seek someones advice. arrayDataOne = [ HEllO, NAME, ADDRESS, ZIPCODE ] i.e [0] = "HELLO" [1] = "NAME" [2] = "ADDRESS" [3] = "ZIPCODE" String arrayInString…
Mad-D
  • 4,479
  • 18
  • 52
  • 93
2
votes
2 answers

array_diff does not show the difference

I'm trying to compare two arrays using this code: $diff = array_diff($selected, $checkboxes); echo '
selected:'; print_r($selected); echo '
original:'; print_r($checkboxes); …
2
votes
0 answers

What is the faster method than array_diff() on PHP?

I'm comparing two arrays which each have 5000 values. (An example value is: 123456789) I want to know if there is a faster way to compare two arrays than array_diff()
Adem
  • 55
  • 3
  • 6
2
votes
1 answer

In place difference between elements of a Numpy array

This is gonna be a fairly simple question to which I wonder if there is a quick and clean workaround in Python. Let say I have a nd-array defined as such: In [10]: C = np.random.rand(2,3,3) In [11]: C Out[11]: array([[[ 0.43588471, 0.06600133, …
macrocosme
  • 473
  • 7
  • 24
1
vote
3 answers

Filter rows of a 2d array by the rows in another 2d array

I have two arrays, and I am using array_diff_assoc() to get the difference, but it always returns the common set row in the result It should be returning the new q sets row. What's wrong with my approach? Sample data: $array1 = [ [12 => 'new q…
1
vote
2 answers

PHP inverse for array_diff_assoc(), remove duplicate values

I haver permissions levels system, so i need remove from my array my previos selected permissions. For example: My permissions: read, write All permissions: read, write, update, delete I need return: update, delete The problem:…
Kin
  • 128
  • 9
1
vote
1 answer

Combine two PHP mysql_fetch_assoc sets of MySQL multidimensional arrays into one single-dimensional array

Would greatly appreciate any help with this. I'm running two mysql_query's to retrieve an array of total bulletins for a specified user in a database from one table (bulletins) and signed bulletins from a second table (bulletins_sign_log). The…
SirOracle
  • 383
  • 2
  • 5
  • 13