A
A
Andrew2016-02-13 21:19:26
PHP
Andrew, 2016-02-13 21:19:26

How to compare two multidimensional arrays in php and keep the same values ​​in both arrays?

Hello, there are two arrays with the names of the actors:

Array
(
    [0] => Array
        (
            [rus_name] => Роберт Дауни мл.
            [eng_name] => Robert Downey Jr.
            [pic] => http://st.kp.yandex.net/images/sm_actor/10096.jpg
            [role] => ... Tony Stark / Iron Man, $ 50 000 000 
        )

    [1] => Array
        (
            [rus_name] => Крис Эванс
            [eng_name] => Chris Evans
            [pic] => http://st.kp.yandex.net/images/sm_actor/49627.jpg
            [role] => ... Steve Rogers / Captain America, $ 2 000 000 
        )

    [2] => Array
        (
            [rus_name] => Марк Руффало
            [eng_name] => Mark Ruffalo
            [pic] => http://st.kp.yandex.net/images/sm_actor/10467.jpg
            [role] => ... Bruce Banner / The Hulk
        )

    [3] => Array
        (
            [rus_name] => Крис Хемсворт
            [eng_name] => Chris Hemsworth
            [pic] => http://st.kp.yandex.net/images/sm_actor/1300401.jpg
            [role] => ... Thor
        )

    [4] => Array
        (
            [rus_name] => Скарлетт Йоханссон
            [eng_name] => Scarlett Johansson
            [pic] => http://st.kp.yandex.net/images/sm_actor/3903.jpg
            [role] => ... Natasha Romanoff / Black Widow, $ 6 000 000 
        )

    [5] => Array
        (
            [rus_name] => Джереми Реннер
            [eng_name] => Jeremy Renner
            [pic] => http://st.kp.yandex.net/images/sm_actor/5468.jpg
            [role] => ... Clint Barton / Hawkeye
        )
)

Array
(
    [0] => Array
        (
            [rus_name] => Роберт Дауни мл.
            [eng_name] => Robert Downey Jr.
            [pic] => http://st.kp.yandex.net/images/sm_actor/10096.jpg
            [role] => ... Tony Stark / Iron Man, $ 500 000 
        )

    [1] => Array
        (
            [rus_name] => Джефф Бриджес
            [eng_name] => Jeff Bridges
            [pic] => http://st.kp.yandex.net/images/sm_actor/6652.jpg
            [role] => ... Obadiah Stane
        )

    [2] => Array
        (
            [rus_name] => Гвинет Пэлтроу
            [eng_name] => Gwyneth Paltrow
            [pic] => http://st.kp.yandex.net/images/sm_actor/3181.jpg
            [role] => ... Pepper Potts
        )

    [3] => Array
        (
            [rus_name] => Терренс Ховард
            [eng_name] => Terrence Howard
            [pic] => http://st.kp.yandex.net/images/sm_actor/1656.jpg
            [role] => ... Rhodey
        )

    [4] => Array
        (
            [rus_name] => Лесли Бибб
            [eng_name] => Leslie Bibb
            [pic] => http://st.kp.yandex.net/images/sm_actor/678.jpg
            [role] => ... Christine Everhart
        )

    [5] => Array
        (
            [rus_name] => Шон Тоуб
            [eng_name] => Shaun Toub
            [pic] => http://st.kp.yandex.net/images/sm_actor/19087.jpg
            [role] => ... Yinsen
        )
)

These arrays contain the names of actors from two different films, it is necessary to calculate the actors who played both there and there, you can, for example, compare by the eng_name field, but I didn’t succeed ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-02-13
@ntzch

$filmActors1 = array_column($arr1, null, 'eng_name');
$filmActors2 = array_column($arr2, null, 'eng_name');

$actors = array_intersect_keys($filmActors1, $filmActors2);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question