I am trying to compare two strings
if they have a same value.
$userP = $userProduct->getProduct();
$userC = $this->get('security.context')->getToken()->getUser()->getProduct();
I want to compare these two in two different array and want compare if userC
has any value that is in userP
.
How can I put them in array and can compare them?
You can compare and find matches in arrays using array_intersect()
:
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_intersect($a1,$a2);
print_r($result);
Output
Array ([a] => red [b] => green [c] => blue)