N
N
Nikolay Matyushkin2018-06-01 12:08:35
PHP
Nikolay Matyushkin, 2018-06-01 12:08:35

How to compare two arrays in a condition?

Hello. The question may be elementary, but still.
How to do for example:
if($arSelect[ID] == $arEnter[ID]){
echo "Arrays are equal";
}else{
echo "Arrays are not equal";
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-06-01
@Yan-s

php.net/manual/en/language.operators.array.php

M
Mysterion, 2018-06-01
@Mysterion

array_diff can be used to compare arrays if you want to compare all elements.

$a = ['a' => 'aa', 'b' => 'bb', 'c' => 'cc', 'd' => 'dd'];
$b = ['a' => 'aa', 'b' => 'bb', 'c' => 'cc', 'd' => 'ddd'];
if($c = array_diff($a,$b)) {
    print_r($c);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question