dongluzhi5208 2019-03-05 13:33
浏览 111
已采纳

array_intersect返回严重性:4096消息:类stdClass的对象无法转换为字符串CodeIgniter

I got two arrays both have multiple values with std Class objects, I want to use 'array_intersect' but it shows "Severity: 4096 Message: Object of class stdClass could not be converted to string"

Controller Code:

    $AlreadyInsertedList = $this->bill->GetBillsbyDate($Givendate); //array1
    $NotInserted = $this->admin->GetACustomersbyArea($areaid);       //array2
    $finallist = NULL;        //finalarray
    $finallist = array_intersect($AlreadyInsertedList,$allcustomersbyarea); //Line number 88 
    //$array = json_decode(json_encode($finallist)); //already tried not working

Although it is giving the required results but with a lot of errors, I'm attaching a screen shot of it, do have a look at the scoll bar (a long length of errors) enter image description here

  • 写回答

1条回答 默认 最新

  • duanmei1946 2019-03-05 22:39
    关注

    This code returns the desired results..

    function ary_diff( $ary_1, $ary_2 ) {   // compare the value of 2 array   // get differences that in ary_1 but not in ary_2   // get difference that in ary_2 but not in ary_1   // return the unique difference between value of 2 array   $diff = array();
    
      // get differences that in ary_1 but not in ary_2   foreach ( $ary_1 as $v1 ) {
        $flag = 0;
        foreach ( $ary_2 as $v2 ) {
          $flag |= ( $v1 == $v2 );
          if ( $flag ) break;
        }
        if ( !$flag ) array_push( $diff, $v1 );   }
    
      // get difference that in ary_2 but not in ary_1   foreach ( $ary_2 as $v2 ) {
        $flag = 0;
        foreach ( $ary_1 as $v1 ) {
          $flag |= ( $v1 == $v2 );
          if ( $flag ) break;
        }
        if ( !$flag && !in_array( $v2, $diff ) ) array_push( $diff, $v2 );   }
    
      return $diff; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部