When I compare two array values I see two strings that look the same. php doesn’t agree.
$array1 = array('address'=>'32 Winthrop Street','state'=>'NY');
$array2 = array('address'=>'32 Winthrop Street');
$results = array_diff_assoc($array1, $array2);
var_dump($results)
//echos ['address'] => string(18) "32 Winthrop Street" ['state']=>'NY'
Why is this?
EDIT
Be advised that this isn’t the actual code I’m testing, I’ve simplified code to illustrate my question, which is about strings being equal, not whether or not this code will run.
Make sure your input arrays really look like that. If you’re echoing data in your browser, you might miss whitespace.
'32 Winthrop Street'is not the same as' 32 Winthrop Street', for example. The same is true for your array keys.You could
$array1 = array_map('trim', $array1)and$array2 = array_map('trim', $array2)to remove leading and trailing whitespace from the values. See if that makes any difference?You can check if they’re really the same by checking
if ($array1['address'] === $array2['address']). If that evaluates to false, there’s a difference, you’re just not seeing it (see binaryLV’s answer for elaboration on a possible cause). If it evaluates to true, you might want to take a closer look at the array keys.