1

I want to check if two arrays are identical. Normally everybody just would use something like this:

if($arrayA == $arrayB){
   //do something...
}

But my question is, how can I check, if the array contains the same values?

For example, array A looks like:

array(2) {
  [0]=>
  array(6) {
    ["price"]=>
    string(5) "50"
    ["shop"]=>
    string(4) "9509"
  }
  [1]=>
    array(6) {
    ["price"]=>
    string(5) "5"
    ["shop"]=>
    string(4) "9509"
  }
}

and array B look like:

array(2) {
  [0]=>
  array(6) {
    ["price"]=>
    string(5) "5"
    ["shop"]=>
    string(4) "9509"
  }
  [1]=>
    array(6) {
    ["price"]=>
    string(5) "50"
    ["shop"]=>
    string(4) "9509"
  }
}

As you can see, only the inner arrays have swaped (5 & 50). But I want to get true. I just want to know if both arrays contain the same informations. Not, if they are completely identical!

How can I check this?

Greetings and Thank You!

Fraze Jr.
  • 143
  • 1
  • 2
  • 10

1 Answers1

0

It sound like your arrays contain different types of data inside, that's not a recommended implementation.

My recommendation my friend is to create an object with all the properties you need and then you can override the method compare extending the interface comparable.

If still you want to compare arrays, try Arrays.equals(arr1, arr2) but they cannot be generic

Eduardo
  • 2,070
  • 21
  • 26