I have two arrays, each generated from a string. The strings are:
$string1 = "#574390, #574387, #574386, #574383 (keyboard enter)
#574368, #574367, #574364, #574361, #574357, #574355, #574351, #574343, #574341 (keyboard enter)
#574381, #574379, #574377, #574375, #574374, #574373, #574372, #574371, #574369"
$string2 = "574390
574386
574383
574381
574379
574377
574375
574374
574373
574372
574371
574369
574368
574367
574364
574361
574357
574355
574351
574343
574341"
Then, I do this to explode each string to array:
$str1 = checkstring($string1);
$str2 = checkstring($string2);
function checkstring($x) {
//check whether the string has "#" in it
if (!strstr($x, '#')) {
$array1 = str_replace(" ", "", $x);
$array1 = explode("\n", str_replace("\r", "", $array1));
return $array1;
}
else {
$array2 = str_replace("\r", ", ", str_replace("#", '', $x));
$array2 = array_unique(explode(", ", $array2), SORT_REGULAR);
return $array2;
}
}
After that, I try to find the difference between the two array:
$result = array_diff($str1, $str2);
print_r($result);
As you can see, the difference between array 1 and array 2 is that in array 1 there is 574387
but not in array 2. The result that I get from the code is this:
Array ( [1] => 574387 [4] => 574368 [13] => 574381 )
And if I switch the value between $string1
and $string2 the result will be this:
Array ( [3] => 574381 [12] => 574368 )
I do the switching because I want to make it able to check both ways. I was wondering what's wrong with it. Thanks for the help.