I
I
Ilya2017-02-20 17:10:20
PHP
Ilya, 2017-02-20 17:10:20

Comparing two array values ​​and outputting data?

Good afternoon, in general, the story is like this, I display some information on the page. In one of the values ​​of the $data array, an array is written - $arr2. I'm trying to compare its values ​​with the $arr1 array. If at least one value matches, information should be displayed. I'm trying to do it like this. I hope for your help.

$arr1 = array(1, 2, 3);

foreach($result as $data) {
    foreach($result_tags as $data_tags) {
        $arr2 = explode(',', $data_tags['id']);
        
        // здесь их нужно сравнить
        for($i = 0; $i < count($arr1); $i++) {
           if(array_search($arr1[$i], $arr2) !== false) { echo 'какая-то информация'; }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad, 2017-02-20
@DaFive

array_intersect ?
Returns the values ​​of elements that are repeated in arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question