0

I have two array.

first array store in $array1;

Array
(
    [status] => 0
    [message] => Already In List
    [result] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => sazib
                    [list_status] => sync
                    [item_list] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 1
                                    [name] => item1
                                    [picture] => 1409220406-apple.png
                                    [purchase_status] => no
                                    [total_quantity] => 7
                                )

                            [1] => Array
                                (
                                    [id] => 2
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 3
                                )

                            [2] => Array
                                (
                                    [id] => 3
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 3
                                )

                            [3] => Array
                                (
                                    [id] => 5
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 4
                                )

                            [4] => Array
                                (
                                    [id] => 6
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 4
                                )

                            [5] => Array
                                (
                                    [id] => 37
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 4
                                )


                        )

                )

            [1] => Array
                (
                    [id] => 3
                    [name] => sazib
                    [list_status] => sync
                    [item_list] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 10
                                    [name] => test
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 3
                                )

                            [1] => Array
                                (
                                    [id] => 11
                                    [name] => prime
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 1
                                )

                        )

                )

        )

)

second array store in $array2

Array
(
    [0] => Array
        (
            [id] => 1
            [list_id] => 1
            [item_id] => 3
        )

    [1] => Array
        (
            [id] => 2
            [list_id] => 1
            [item_id] => 5
        )

    [2] => Array
        (
            [id] => 3
            [list_id] => 3
            [item_id] => 11
        )

)

now if first array compare with second array.depend on given example

here first array first index id 1 match with second array [0] and [1] so from first array this list item will be deleted .also other like same.

after calculation output will be

Array
(
    [status] => 0
    [message] => Already In List
    [result] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => sazib
                    [list_status] => sync
                    [item_list] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 1
                                    [name] => item1
                                    [picture] => 1409220406-apple.png
                                    [purchase_status] => no
                                    [total_quantity] => 7
                                )

                            [1] => Array
                                (
                                    [id] => 2
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 3
                                )

                            [2] => Array
                                (
                                    [id] => 3
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 3
                                )



                            [4] => Array
                                (
                                    [id] => 6
                                    [name] => item1
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 4
                                )



                        )

                )

            [1] => Array
                (
                    [id] => 3
                    [name] => sazib
                    [list_status] => sync
                    [item_list] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 10
                                    [name] => test
                                    [picture] => 
                                    [purchase_status] => no
                                    [total_quantity] => 3
                                )

                        )

                )

        )

)

I am confused how can i calculate it.

I want if any list_id($array2) match with first array checking every item [id] then delete ($array1) [item_list] array item match with [item_id] corresponding [list_id] () from matched item [id] of first array.

Please compare my given expected result array with given $array1 and $array2

3
  • 1
    Please say what you want more simply. I can't really figure out what you want.
    – Jay
    Commented Sep 4, 2014 at 21:29
  • I cannot figure out what exactly your criteria is. Could you provide something like: This element should be in my final output because $array1['result'][0]['item_list'][0]['id'] == $array2[0]['item_id']? Anyhow: You should maybe reconsider your array structure as it is quite confusing.
    – newBee
    Commented Sep 4, 2014 at 22:22
  • This looks like something for a database so that you can query data rather than working with awkwardly sized arrays.
    – Kolors
    Commented Sep 4, 2014 at 22:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.