匹配php中多维数组的每个索引

时间:2016-09-01 11:52:05

标签: php arrays multidimensional-array

我有一个像这样的数组

   $msg =  Array
(

    [0] => stdClass Object
        (
            [id] => 638
            [user_id] => 358253
            [raw_text] => Your package with Philips QG3387 Multi Grooming Kit (Black) has been successfully delivered. Thank you for choosing us.
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => DELIVERY_STATUS
            [product_description] => Philips QG3387 Multi Grooming Kit (Black)

        )

    [1] => stdClass Object
        (
            [id] => 641
            [user_id] => 358253
            [raw_text] => Your package with Philips QG3387 Multi Grooming Kit (Black) could not be delivered as addressee was not available. www.amazon.in/track
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => DELIVERY_STATUS
            [product_description] => Philips QG3387 Multi Grooming Kit (Black)

        )



    [2] => stdClass Object
        (
            [id] => 907
            [user_id] => 358253
            [raw_text] => Dispatched: Your package with Gadget Advice 720*480 Newest Smiley Face DVR Hidden S... will be delivered on or before 16-Jul. Track at http://amzn.in/5bIkuau
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => 
            [product_description] => Your package with Gadget Advice 720*480 Newest Smiley Face DVR Hidden S...

        )

    [3] => stdClass Object
        (
            [id] => 910
            [user_id] => 358253
            [raw_text] => Your order with order id 171-5257992-6082713 has been successfully placed. Please check email for more details. Thank you for shopping at Amazon.
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => 
            [product_description] => 

        )

    [4] => stdClass Object
        (
            [id] => 914
            [user_id] => 358253
            [raw_text] => Your order with order id 404-4813325-2653153 has been successfully placed. Please check email for more details. Thank you for shopping at Amazon.
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => 
            [product_description] => 

        )

    [5] => stdClass Object
        (
            [id] => 922
            [user_id] => 358253
            [raw_text] => Your package with Philips QG3387 Multi Grooming Kit (Black) has been successfully delivered. Thank you for choosing us.
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => DELIVERY_STATUS
            [product_description] => Philips QG3387 Multi Grooming Kit (Black)

        )

    [6] => stdClass Object
        (
            [id] => 925
            [user_id] => 358253
            [raw_text] => Your package with Philips QG3387 Multi Grooming Kit (Black) could not be delivered as addressee was not available. www.amazon.in/track
            [type_of_message] => ECOMMERCE
            [sub_type_of_message] => DELIVERY_STATUS
            [product_description] => Philips QG3387 Multi Grooming Kit (Black)

        )
)

我想为每个索引比较$ msg [0] [product_description]和$ msg [1] [product_description]并创建一个新数组

if($msg[0][product_description] != $msg[1][product_description]) then $newArr[] = $msg[0][product_description]
if($msg[0][product_description] == $msg[1][product_description]) then $newArr[] = $msg[1][product_description]
if($msg[1][product_description] == $msg[2][product_description]) then $newArr[] = $msg[2][product_description]

如果值相同,我想将$ msg [0] [product_description]与其他索引进行比较,然后将该索引移动到新数组。与其他索引相比较。 请帮忙

0 个答案:

没有答案