У меня есть этот xml, который содержит четыре текстовых сообщения, и я преобразовал их в массив.array_diff для сложного xml
XML-
> <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
> <?xml-stylesheet type="text/xsl" href="sms.xsl"?> <smses count="4">
> <sms protocol="0" address="0800000" date="1328814938421" type="2"
> subject="null" body="Its raining cat and dogs;and their owners."
> toa="null" sc_toa="null" service_center="null" read="1" status="-1"
> locked="0" date_sent="null" readable_date="Feb 9, 2012 10:15:38 PM"
> contact_name="Hans Petit" />
> <sms protocol="0" address="08005678" date="1328814938421" type="2" subject="null" body="Hello,Andy.The attachment wasn't
> sent.Please resend." toa="null" sc_toa="null" service_center="null"
> read="1" status="-1" locked="0" date_sent="null" readable_date="Feb 9,
> 2012 10:15:38 PM" contact_name="Mary The Great" />
> <sms protocol="0" address="080091011" date="1328814938421" type="2" subject="null" body="Lorem Ipsum = Good Night." toa="null"
> sc_toa="null" service_center="null" read="1" status="-1" locked="0"
> date_sent="null" readable_date="Feb 9, 2012 10:15:38 PM"
> contact_name="Ed Myers" />
> <sms protocol="0" address="+44839202" date="1328815215841" type="1" subject="null" body="I represent a variable." toa="null"
> sc_toa="null" service_center="+4422500000" read="1" status="-1"
> locked="0" date_sent="null" readable_date="Feb 9, 2012 10:20:15 PM"
> contact_name="Dexter" />
> <sms protocol="0" address="+2273839309" date="1329194575094" type="1" subject="null" body="Take it easi" toa="null" sc_toa="null"
> service_center="+4422500000" read="1" status="-1" locked="0"
> date_sent="null" readable_date="Feb 14, 2012 7:42:55 AM"
> contact_name="Miguel" /> </smses>
Массив
Array ([SMS-сообщения] => Array ([SMS] => Array ([0] => Array() [1] => Array() [0_attr] => Array ([protocol] => 0 [address] => 0800000 [date] => 1328814938421 [type] => 2 [subject] => null [body] => дождь кошки и собаки, и их владельцы. [toa] => null [sc_toa] => null [service_center] => null [read] => 1 [status] => -1 [locked] => 0 [date_sent] => null [readable_date] => 9 февраля 2012 г. 10:15:38 [contact_name] => Hans Petit) [1_attr] => Массив ([протокол] => 0 [адрес] => 08005678 [date] => 1328814938421 [type] => 2 [subject] => null [body] => Здравствуйте, Энди. Вложение не было отправлено. Повторите отправку. [toa] => null [sc_toa] => null [service_center] => null [read] => 1 [status] => -1 [locked] => 0 [date_sent] => null [readable_date] => 9 февраля 2012 г. 10:15:38 [contact_name] => Mary The Great) [2] => Array() [2_attr] => Array ([protocol] => 0 [address] => 080091011 [ дата] => 1328814938421 [type] => 2 [subject] => null [body] => Lorem Ipsum = Good Night. [toa] => null [sc_toa] => null [service_center] => null [читать ] => 1 [статус] => -1 [заблокирован] => 0 [date_sent] => null [readable_date] => 9 февраля 2012 г. 10:15:38 [contact_name] => Ed Myers ) [3 ] => Array() [3_attr] => Array ([protocol] => 0 [address] => +44839202 [date] => 1328815215841 [type] => 1 [subject] => null [body] => Я представляю переменную. [toa] => null [sc_toa] => null [service_center] => +4422500000 [read] => 1 [status] => -1 [locked] => 0 [date_sent] => null [readable_date] => 9 февраля 2012 г. 10:20:15 [contact_name] => Dexter) [4] => Array() [4_attr] => Array ( [protocol] => 0 [address] => +2273839309 [date] => 1329194575094 [type] => 1 [subject] => null [body] => Возьмите его easi [toa] => null [sc_toa] => null [service_center] => +4422500000 [читать] => 1 [status] => -1 [заблокирован] => 0 [date_sent] => null [readable_date] => 14 февраля 2012 г. 7:42:55 AM [contact_name] => Miguel))) [smses_attr] => Array ( [count] => 4))
У меня есть другой XML-документ 2, который я изменил только одно значение - адрес = «0800000» в первый, который является адресом = «0900000» в second.When я сравнить два массива с помощью
include "xml2array.php";
$contents = file_get_contents('sms.xml');//Or however you what it
$result = xml2array($contents);
//print_r($result);
$contents_ = file_get_contents('smsz.xml');//Or however you what it
$result_ = xml2array($contents_);
//print_r($result_);
$result_diff = array_diff($result, $result_);
print_r($result_diff);
я получаю, который не является что я ожидал.
Массив()
Я ожидал что-то вроде
Array
(
[1] => 0900000
)
Может быть, значения точно такие же – Starx
nope, у меня есть массив 2, который я немного изменил. Я не мог вставить его здесь, страница становилась слишком огромной. – Gandalf