Array_diff获取错误数组到字符串转换php

时间:2016-11-02 15:04:29

标签: php codeigniter codeigniter-3

我想使用此代码的array_diff我也得到输出但同时发生错误

“数组到字符串转换”

我正在使用codeigniter,我在第二个数组(listingdata)中使用方法$ this-> input-> post(); ,但是我的第一个数组获得了一些动态键和值,然后这两个数组diff给了我输出但是有时候会出错。

请帮帮我

任何解决方案总是受欢迎。

 if(isset($_POST)){
                foreach($_POST as $key => $value) {

                    $arr[$key] = $value; // making array 
                }
            }

            $result = array_diff($arr,$listingdata);
            print_r($result);
            print_r($arr);
            print_r($listingdata);

我的$ arr数组

Array
(
    [itemTitle] => fdafdas
    [subtitle] => fadsfdas
    [quantity] => 12
    [itemDescription] => fdas
    [hide_ebay_id] => 89
    [ebay_user] => Array
        (
            [0] => 
        )

    [ebay_category] => 2984
    [e_sub_cat] => 20433
    [e_second_child_sub_cat] => 117027
    [e_third_child_sub_cat] => 
    [ebay_upc] => 31231241341
    [Brand] => Unbranded
    [MPN] => Does_Not_Apply
    [Model] => fsdf
    [Country/Region_of_Manufacture] => Unknown
    [listingType] => FixedPriceItem
    [listingduration] => Days_5
    [buy_it_now_price] => 20.00
    [shippingtype] => Flat
    [fshippingservice] => USPSPriorityFlatRateBox
    [shippingservicecost] => 2.0
    [shippingsac] => 3.0
    [internationalhc] => 
    [paypalemailaddress] => sam@jaff.in
    [dispatchtimemax] => 3
    [location] => CA
    [ebaycountry] => 
    [ebay_paypalemail] => 
    [ReturnsAccepted] => ReturnsAccepted
    [returnswithin] => Days_14
    [refundoption] => MoneyBack
    [shippingcostpaidbyoption] => Seller
    [policydescription] => wqdewvfdgbfdggrbf
)

这是我的另一个数组

Array
(
    [itemTitle] => fdafdas
    [subTitle] => fadsfdas
    [categoryId] => 117027
    [itemDescription] => fdas
    [listingType] => FixedPriceItem
    [listingDuration] => Days_5
    [startPrice] => 
    [buyItNowPrice] => 20.00
    [quantity] => 12
    [upc] => 31231241341
    [paypalEmailAddress] => sam@jaff.in
    [returnWithin] => Days_14
    [RefundOption] => MoneyBack
    [ShippingCostPaidByOption] => Seller
    [returnsAccepted] => ReturnsAccepted
    [shippingType] => Flat
    [cshippingService] => 
    [fshippingService] => USPSPriorityFlatRateBox
    [dcPostalcode] => 
    [ShippingServiceCost] => 2.0
    [dshippingPackage] => 
    [shippingHandlingcost] => 
    [shippingServiceAdditionalCost] => 3.0
    [currency] => USD
    [country] => 
    [location] => CA
    [dispatchTimeMax] => 3
    [pictureUrl] => Array
        (
            [0] => http://jaftech.in/ashprey/uploads/69.jpg
        )

    [policyDescription] => wqdewvfdgbfdggrbf
    [internationalShipping] => 
    [internationalShippingType] => 
    [internationalShippingServiceCost] => 
    [internationalshippingServiceAdditionalCost] => 
    [cinternationalshippingService] => 
    [finternationalshippingService] => 
    [internationalShipToLocation] => 
    [internationaloriginatingPostalCode] => 
    [internationalshippingHandlingcost] => 
    [ishippingPackage] => PackageThickEnvelope
    [pid] => 89
)

1 个答案:

答案 0 :(得分:0)

这是因为array_diff比较了两个比较值与字符串后的值(参见documentation notes)。

您的两个数组都包含另一个数组(ebay_user和第二个pictureUrl)。

请参阅this answer了解递归数组_diff,它适用于您的情况。