【问题标题】:array_intersect returns Severity: 4096 Message: Object of class stdClass could not be converted to string CodeIgniterarray_intersect 返回严重性:4096 消息:stdClass 类的对象无法转换为字符串 CodeIgniter
【发布时间】:2019-07-27 11:02:38
【问题描述】:

我有两个数组都有多个 std Class 对象的值,我想使用 'array_intersect' 但它显示“严重性:4096 消息:stdClass 类的对象无法转换为字符串”

控制器代码:

    $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

虽然它给出了所需的结果,但有很多错误,我附上了它的屏幕截图,请看一下 scoll 栏(很长的错误)

【问题讨论】:

    标签: php arrays object stdclass array-intersect


    【解决方案1】:

    此代码返回所需的结果..

    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; }
    

    【讨论】:

    • 如果此代码对您有用,那么您可以接受您自己的答案,所以请这样做,以便关闭问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多