A
A
Alexander Andropov2021-07-30 18:16:11
PHP
Alexander Andropov, 2021-07-30 18:16:11

How to compare Two Arrays with condition?

Good day friends. There are two datasets. I get one from a DB, I get the second from other server. Structurally, they are the same.
I need to compare these two arrays, but at the same time, they are the same strings.

Array A contains: name, age, avatar. Array B contains the same. I need to check. If arrayA[name] == arrayB[name], then perform the operation.

Confused about loops, how do I fully compare two arrays, provided that their name field is equal to the same value ?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Yakovlev, 2021-07-31
@sergeyakovlev

$diff = array_diff_assoc($a, $b);
if (count($diff)) {
    // массив $b отличается от массива $a
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question