How to compare two arrays with condition using 'array_uintersec'?

Viewed 50

I have the next arrays:

$noticias = [
    "0" => Array(
        "codigo" => "AMBITO"),
    "1" => Array(
        "codigo" => "ELSOL"),
    "2" => Array(
        "codigo" => "MDZ")
    ]

$portales = [
    "0" => Array(
        "codigo" => "LOSANDES"),
    "1" => Array(
        "codigo" => "MDZ"),
    "2" => Array(
        "codigo" => "ELSOL")
    ]

I need to compary both arrays by attribute codigo. The result would be:

$result = [
    "1" => Array(
        "codigo" => "ELSOL"),
    "2" => Array(
        "codigo" => "MDZ")
    ]

How can i do? At this moment, i have this:

$noticias_provinciales = array_uintersect($noticias, $portales, function($noticia, $portal_provincial){            
                $portal_codigo_noticia = $noticia['Portal__codigo'];
                $portal_codigo_provincial = $portal_provincial->codigo;
                return ($portal_codigo_noticia === $portal_codigo_provincial ? 0: 1);            
            });

But it doesn't work for me. I was debbuging and i notice that the both variables $noticia and $portal_provincial are from the same array ($noticia). I want that the first variable from function be $noticia (from $noticias) and the second one be $portal (from $portales). How can i do this?

Thanks!

2 Answers
Related