I have a form field called $_POST['hidden-tags']
It has values entered in as follows
cars, vans, bikes, trains,
I on post im trying to split the values and save them into an array and then compare that array with another I have and only display the values that are different. I know the $arr1 has values as I have tested the data.
the code I have so far is
$arr1;
$arr2 = array();
foreach($_POST['hidden-tags'] as $value){
$arr2[] = explode(",",$value);
}
print_r($arr2);
// $tmp = array_diff_key($arr1, $arr2);
// echo $tmp;
parts of which I found here on stack
PHP explode array
As you can see I have the final bit commented out. This is so I can see the array values. If I echo the $arr2 all I see on screen is
Array()
even though I have entered cars, bikes, vans. I have not got as far as comparing the two array yet and displaying the $tmp variable
Is
$_POST['hidden-tags']a text input field? If so, you don’t need to run aforeachon it to split it into an array. Just explode it and compare the generated array with the one you already have.