A
A
Andreas Machis2019-08-01 07:11:51
PHP
Andreas Machis, 2019-08-01 07:11:51

How to get a new array after comparing two arrays?

Hello!!
Please do not kick me, I'm self-taught .. and now I just can't understand how I can compare two arrays and get two new arrays based on the comparison.
I would be very grateful for your help!
So there are two arrays:

$fin_array = Array
(
    [Номер телефона] => +79609998877
    [Номер карты] => 
    [Номер трека] => 
    [Фамилия] => Пасюков
    [Имя] => Сергей
    [Отчество] => 
    [Пол] => М
    [Дата рождения] => 22.09.1906
    [Возраст] => 32
    [Ранг] => Серебряный
    [Проц инд бонуса] => 0.00
    [Проц инд скидки] => 0.00
    [Комментарий] => 
    [Средний чек] => 1.00
    [Количество чеков] => 1
    [Частота посещений] => 0.00
    [Сумма чеков] => 1.00
    [Оплачено деньгами] => 1.00
    [Бонусов потрачено] => 0.00
    [Бонусов накоплено] => 0.00
    [Баланс бонусов] => 0.08
    [Последний заказ] => 20.06.2017
    [Первый заказ] => 20.06.2017
    [ПолОтзывы] => 1
    [ОтрОтзывы] => 0
    [Дата регистрации] => 20.06.2017
    [Анкета заполнена] => Нет
    [Дата заполнения анкеты] => 
    [Email] => [email protected]
    [Cогласие на email] => Да
    [Телефон подтвержден] => Да
    [Cогласие на SMS] => Нет
    [Cогласие на push] => Да
    [Источник] => Front
    [Источник (Админ)] => API старых фронтов
);

$temp_cont_arr= Array
(
    [Номер телефона] => +79291112233
    [Имя] => Анна Самойлова
);

you need to check them, so that if the phone number from the first one is in the second one, then enter the data from the keys and values ​​of the first array ($fin_array) into the new array $cont_update (update), i.e. those that were found
if the phone number from the first is not in the second, make $cont_create (create) from the keys and values ​​of the first array ($fin_array) i.e. those that were not found

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony Tkachenko, 2019-08-01
@LemonFox

if ($fin_array['Номер телефона'] === $temp_cont_arr['Номер телефона']) {
    $newData = array_merge($fin_array, $temp_cont_array);
}

https://www.php.net/manual/ru/language.types.array.php
https://www.php.net/manual/ru/function.array-merge.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question