There are two arrays with names. Write in the third array the names that are the same from the first and second array.

Array( [0] => stdClass Object ( [login] => serg123 ) [1] => stdClass Object ( [login] => turb0 ) 

)

 Array( [0] => stdClass Object ( [login] => Maksim ) [1] => stdClass Object ( [login] => turb0 ) 

)

in the third array should be

 Array( [0] => stdClass Object ( [login] => turb0 ) 

    1 answer 1

    Let's use the function array_intersect - which returns the matches for the values ​​in the arrays. First you need to get rid of objects in arrays. For each array, do so

     $arr1 = array(); foreach($arr_source_1 as $o) { $arr1[] = $o->login; } 

    similarly, we get $ arr2 for the second array

    Next we find the intersection of these arrays

     $arr_int = array_intersect($arr1, $arr2); 

    and form the resulting array

     $arr_res = array(); foreach ($arr_int as $v) { $o = new stdClass(); $o->login = $v; $arr_res[] = $o; } 
    • Hey. Thank. I changed the question. - Maksim
    • @Maksim can’t be done that way - Alexey Shimansky
    • Sorry I'm confused and not asked. - Maksim