Cross-Match values in 2 arrays?

#1 Array ( [0] => Array ( [asciiname] => zurgena [id] => 1 ) [1] => Array ( [asciiname] => zuniga [id] => 2 ))



#2 Array ( [0] => Array ( [s_slug] => zurgena ) [1] => Array ( [s_slug] => a ameixenda ) [2] => Array ( [s_slug] => a baiuca ) [3] => Array ( [s_slug] => a barqueira ))

These arrays are not the same!

How can I take each value from array #2 and check it matches any value in array #1 if so output the ID from array #2???

Could you use array_intersect() to do it?

http://php.net/manual/en/function.array-intersect.php

I have no idea how to do it please give me some pointers some code to work with using my arrays

<?php
$array1 = array("a" => "green", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
print_r($result);
?> 

Example code from the page I linked to. I think you might have to swap array1 and array2.

Thanks but it doesn’t work with my multidimensional arrays!

I am trying to foreach both of them but it takes forever since I am comparing like 200k values!!!

Ah, sorry about that.

Are you building the arrays from data extracted from a database table, and if so, might it be quicker to figure out a query to do the job instead? I would imagine that any built-in function is only going to be doing pretty much the same as you can do yourself with a foreach() so probably wouldn’t be significantly quicker.

Thanks buddy but I have tried SQL table match, slow as hell plus I need PHP to prepare the data before matching like removing some symbols!

How can we do that please?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.