How to remove similar objects using checking a field of those?

Posted 5 months ago by alihoushyaripour

Hi,

I have 2 object array with name var1 and var2.

Assumption:

always count($var2) <= count($var1)

objects schema:

{
    "code", // integer
    "status_code" // boolean
}

$var1:

[
    {
        "code": 1,
        "status_code": false
    },
    {
        "code": 2,
        "status_code": false
    },
    {
        "code": 3,
        "status_code": false
    },
    {
        "code": 4,
        "status_code": false
    },
    {
        "code": 5,
        "status_code": false
    },
    {
        "code": 6,
        "status_code": false
    },
    {
        "code": 7,
        "status_code": false
    },
    {
        "code": 8,
        "status_code": false
    },
    {
        "code": 9,
        "status_code": false
    },
    {
        "code": 10,
        "status_code": false
    },
    {
        "code": 11,
        "status_code": false
    },
    {
        "code": 12,
        "status_code": false
    },
    {
        "code": 13,
        "status_code": true
    },
    {
        "code": 14,
        "status_code": false
    },
    {
        "code": 15,
        "status_code": false
    }
]

$var2:

[
    {
        "code": 1,
        "status_code": true
    },
    {
        "code": 2,
        "status_code": false
    },
    {
        "code": 4,
        "status_code": true
    },
    {
        "code": 8,
        "status_code": true
    },
    {
        "code": 10,
        "status_code": false
    },
    {
        "code": 15,
        "status_code": false
    }
]

Now I want to combine these 2 objective array, in condition that there is no repetition based on code field and if status_code value in the $var2 array is replaced to $var1

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.