TheMerovingian TheMerovingian - 5 months ago 17
PHP Question

array_key_exist() with array as key

I'm trying to check if in an array there is any value of another array. The function

array_key_exist()
looks like what I'm searching for, but I don't understand how to give the key value at the function as an array. Here's the code:

$risultato_query_controllo_numero = mysql_query($query_controllo_numero);
$voucher_esistenti = array();

while(($row = mysql_fetch_assoc($risultato_query_controllo_numero))) {
$voucher_esistenti[] = $row['numero'];
}


Which populates the first array with numbers:

$voucher = range($numero, $numero + $quantita);


Which populates the second array with numbers.

What I need to do now is to check if any of the value in
$voucher
is present in
$voucher_presenti
.

Answer

You can use the array_intersect function:

$overlap = array_intersect($voucher, $voucher_presenti); 

You can find more examples in the documentation.

Comments