Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP arrays: cross data

Tags:

arrays

php

An student here who needs help with the logic of the following:

I have two arrays.

$array1 contains the ids of the places the user has been to.

$array2 contains the ids of the places where the user can obtain one point just by visiting them

Now I need to know if the user has visited any of the places where he/she can get one point so I can grant it to him/her. How can I do that?

Tnaks a lot

like image 264
ADM Avatar asked Apr 06 '26 07:04

ADM


2 Answers

Looks like you want to try array_intersect

$intersection = array_intersect($array1, $array2);
like image 55
Brian Driscoll Avatar answered Apr 08 '26 21:04

Brian Driscoll


count(array_intersect($array1, $array2)) should then give you the number of suych places.

like image 36
Artefacto Avatar answered Apr 08 '26 21:04

Artefacto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!