The $category variable will either hold values (i.e. tags) that are already available in the tags table, or the user can enter new tags in this variable , or both.
Following is the query that brings tags if they are available in the tags table:
$TagNames = DB::table('tags')
->whereIn('t_name', $category)
->pluck('t_name');
The output of TagNames :
array(2) { [0]=> string(7) "Zamalek" [1]=> string(4) "Ahly" }
Below is the $category variable that will hold all the tags, regardless they are new tags entered by the user, or existing ones.
$category = $request->get('catBox');
Output of $category (with two additional new tags) :
array(4) { [0]=> string(7) "Zamalek" [1]=> string(4) "Ahly" [2]=> string(5) "Gouna" [3]=> string(8) "Pyramids" }
The question is : How can I compare both arrays and get only the difference (i.e. "Gouna" and "pyramids" in this case) in a new array ?