I have the following code:

$base = "111111,222222,333333"; $xml = " <item> <id>111111</id> <status>cancel</status> <status_ext>test_order</status_ext> </item> <item> <id>222222</id> <status>cancel</status> <status_ext>test_order</status_ext> </item> "; $base_arr = explode(',', $base); preg_match_all('#<id>(.*?)</id>#', $xml, $xml_arr); $result_not_xml = array_diff($base_arr, $xml_arr[0]); print_r($base_arr); print_r($xml_arr[0]); print_r ($result_not_xml); 

I get the output - as if none of the elements of $base_arr are contained in $xml_arr[0] :

Array ([0] => 111111 [1] => 222222 [2] => 333333)

Array ([0] => 111111 [1] => 222222)

Array ([0] => 111111 [1] => 222222 [2] => 333333)

I did not understand how to fix ...

1 answer 1

Error in line:

 $result_not_xml = array_diff($base_arr, $xml_arr[0]); 

Need to change to:

 $result_not_xml = array_diff($base_arr, $xml_arr[1]); 

Since the zero index contains the full entry string. That is, along with the tags <id> ... </ id>. Perhaps you watched the output in html mode, in which the tags turned into tags.