我有两个带有std类对象的数组,它们都具有多个值,我想使用'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
答案 0 :(得分:0)
此代码返回所需的结果。
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; }