1

I have 2 arrays (array1 and array2). I want to compare these arrays and need the array rows back which do not exist in array2.

Here is array 1

Array
(
    [0] => Array
        (
            [image_id] => 4
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [1] => Array
        (
            [image_id] => 3
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [2] => Array
        (
            [image_id] => 2
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [3] => Array
        (
            [image_id] => 1
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
)

Here is array2

Array
(
    [0] => Array
        (
            [image_id] => 1
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
    [1] => Array
        (
            [image_id] => 4
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
)

Desired result:

Array(
    [0] => Array
        (
            [image_id] => 3
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )

    [1] => Array
        (
            [image_id] => 2
            [user_id] => 2
            [user_type] => user
            [canvas_id] => 1
            [canvas_mac] => 123.234.232.121
        )
)
1

1 Answer 1

2

Please try array_udiff (http://php.net/array_udiff). Does it meet your requirements?

Sign up to request clarification or add additional context in comments.

3 Comments

I don't think so it would work for me because the method you mentioned above its multiplying the object values and making comparison but i have alphabets in my array too an as well as i need the same value on other array too no difference like above method even taking equal to this height = 2, width = 4 height = 4, width = 2 above method said its equal but i need it same like this height = 2, width = 4 height = 2, width = 4 Now it is equal
@AboBaker "its multiplying the object values" <-- that's non-sense. That is simply not happening. 3v4l.org/aAe7j If you need more granular comparison operations, you'll need to improve your minimal reproducible example and better explain how the rows should be compared.
@mickmackusa I was resolved this issue by myself. Around 6 years ago. You did respond very late to this conversation. Anyhow thanks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.