Question

i have a problem with array_diff.

I have a textarea with legal email-adresses. I get these from a mysql-database. When i insert them into the textarea i also save them in an array.

When the form is submited i have a function who takes the content of the textarea and compares it with the first array. In that way i can see if the user has added another email-adress.

My problem is that the array_diff outputs the whole array, not the elements that are different.

I have tried to output the arrays before they are compared and they both have the right values. When i tried with dummy arrays with hardcoded values the output is correct.

What can cause this?

Was it helpful?

Solution

That depends on how you're adding to the textarea, and how you're getting them back.

Assuming you have the email addresses in indivudual strings in the database, you might be combining them with \n in the textarea, then explodeing on \n... but if you're running Windows then the lines are separated by \r\n, so you'd be comparing email@example.com with email@example.com\r, which is different. This would cause the entire array to be listed, without any visible cause.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top