dongsheng1238 2013-09-27 06:14
浏览 56
已采纳

PHP从3维数组中获取数组值

Hello i have array with 3 dimension. the main array hold 3 message sets and each message sets hold 10 messages. i need to show the message data on page

i used this code for generate array.

$messages=array();
for ($i = 1; $i <= 3; $i++) {
$messages[]=$sqs->receiveMessage('https://sqs.us-west-2.amazonaws.com/947693316473/amazon_notification',10);
}
var_dump($messages);

the var dump gives me this reults(part of var dump)

array(3) { [0]=> array(2) { ["RequestId"]=> string(36) "38e56e19-c186-5057-aafc-24a6e3b8b9c0" ["Messages"]=> array(10) { [0]=> array(4) { ["MessageId"]=> string(36) "64419fb5-b824-4475-83e1-bd004bfcb413" ["ReceiptHandle"]=> string(288) "uUk89DYFzt3DGyM6Ey52yPUINfIRCkqjuwyXM1T2gNKWmdVIPAztgX2pS1rpj6bplAYqKFx3hsPU3ZyZ4ZH0zgazEsAPOaD28PwavMIOWfhca8D6zElXbgCv+tU0ShXAyA9NcqxcZPCAAHK3UYph2PEVd2ihk+hkTOGvu4Js2xnGozrnaRY1bUH7sZ87K2J/a3Kd8Pl6RAhVUFwVCfGpH4NkhdyduXMwkmrAKNQawRkwFmB9myDbEYBh9zpJdusnMcrTDl3F8F+yWEwphtPMxH4UijoDsgSo" ["MD5OfBody"]=> string(32) "b9236bf0f013145da92cf27619b414f7" ["Body"]=> string(13840) " AnyOfferChanged 1.0 7b49b7eb-2eab-4d35-a17c-6cdaef89edda 2013-09-27T05:05:29.629Z A34FW7RM36DHBT A1PA6795UKMFR9 A1PA6795UKMFR9 B0036F7WHU new 2013-09-27T05:05:28.746Z 37 1 81.89 EUR 81.89 EUR 0.00 EUR 82.47 EUR 82.47 EUR 0.00 EUR 82.47 EUR 82.47 EUR 0.00 EUR 73.10 EUR 32 1 A1HTKBNYG718CQ new 49993 93 81.89 EUR 0.00 EUR DE false Unsere Artikeldaten zum Vergleich: BT-Modul 40 BT-Modul 40 - Bluetooth-Modul f&uuml;r Tele false true true false A3JWKAKR8XB7XF new 0 82.47 EUR 0.00 EUR true false true true false A31522I6NTHR25 new 31475 99 82.17 EUR 4.00 EUR DE false true true true true AOC3G2PBG3IY7 new 621523 96 86.63 EUR 0.00 EUR DE false TK Anlage ISDN Zub AGFEO BT Modul 40. Fabrikneu & OVP. Rg mit ausgew. MwSt. 2 Jahre Gew&#2 false true true true A1AL0IFPG5W1BM new 197465 93 88.97 EUR 0.00 EUR DE false NEUWARE mit Rechnung und ausgewiesener MwSt. DHL Versand! Packstationen und Postfächer mög false true true false A18KZ5Y7JZEYT0 new 779 91 92.55 EUR 0.00 EUR DE false ----Wir verschicken nicht an Packstationen---- BTMODUL 40 Bluetooth Modul 40 Die Einzel un false true true false A189RWP0VCRW62 new 16456 96 93.00 EUR 0.00 EUR DE false false true true true A2RQ26FRS9UTKN new 8190 96 88.75 EUR 6.89 EUR DE false geliefert wird: Artikelname: Bluetoothmodul BT-Modul 40, Hersteller: AGFEO, Herstellerarti false true true true A2TJA1FXIZNS2O new 1330 96 96.29 EUR 0.00 EUR DE false Neu OVP; Versand per DHL aus Deutschland, auch an Packstation, nur 1x Versandkosten pro Li false true true true A31XRU8TFBHI66 new 633 96 95.11 EUR 4.09 EUR DE false AGFEO Bluetoothmodul für ST 40 6101031 false true true false A133RA3ZUAU4I7 new 40406 93 101.62 EUR 0.00 EUR DE false false true true true A34FW7RM36DHBT new 4873 94 102.81 EUR 0.00 EUR DE false false true true true " } [1]=> array(4) { ["MessageId"]=> string(36) "d50624ce-d0d0-4d31-b762-0fcbc826dd07" ["ReceiptHandle"]=> string(288) "uUk89DYFzt3DGyM6Ey52yPUINfIRCkqj79dpqDDeT9vENqvOve6dd1Kdx+bm0rUr7SnaAYm35nHU3ZyZ4ZH0zgazEsAPOaD28PwavMIOWfhca8D6zElXbgCv+tU0ShXAyA9NcqxcZPCAAHK3UYph2PEVd2ihk+hkTOGvu4Js2xnGozrnaRY1bUH7sZ87K2J//bvMYBQZeQoz7fn8u387bYQnnWVg1xEdrPo2e2/OHrYBnQQTDtuzmxTMS8y8UFB2ujqQ7FuGbGOyWEwphtPMxH4UijoDsgSo" ["MD5OfBody"]=> string(32) "40e3dba34cc8fec44679d64d11806808" ["Body"]=> string(16357) " AnyOfferChanged 1.0 a116d8d2-fea4-4287-b146-91b3671fa19c 2013-09-27T05:05:32.383Z A34FW7RM36DHBT A1PA6795UKMFR9 A1PA6795UKMFR9 B004F1F5B4 new 2013-09-27T05:05:31.044Z 46 1 18.06 EUR 18.06 EUR 0.00 EUR 18.72 EUR 18.72 EUR 0.00 EUR 18.06 EUR 18.06 EUR 0.00 EUR 20.99 EUR 32 1 AOC3G2PBG3IY7 new 621523 96 18.06 EUR 0.00 EUR DE false Adapter / USB / Wless N / NWD-2205. Neu. Rechnung mit ausgew. MwSt. 2 Jahre Gew&#228;hrlei false true true true A1HTKBNYG718CQ new 49993 93 18.07 EUR 0.00 EUR DE false Unsere Artikeldaten zum Vergleich: NEW WLAN USB ZYXEL NWD-2205 bis 300Mbit, Wireless LAN I false true true false A1X0M9U5WW1195 new 670945 95 18.10 EUR 0.00 EUR DE false false true true true A4JBMX2FM5537 new 54060 94 18.40 EUR 0.00 EUR DE false false true true true A3JWKAKR8XB7XF new 0 18.72 EUR 0.00 EUR true false true true false A133RA3ZUAU4I7 new 40406 93 18.99 EUR 0.00 EUR DE false false true true true A34FW7RM36DHBT new 4873 94 19.37 EUR 0.00 EUR DE false false true true true AZLS81A4R7CR4 new 7521 98 19.83 EUR 0.00 EUR DE false Neuware. Versand aus Deutschland. Service und technische Unterstützung per Email und Tele false true true false A3CJ7XH8N58PQ7 new 44289 90 15.48 EUR 4.40 EUR DE false . true true true true A1AL0IFPG5W1BM new 197465 93 19.88 EUR 0.00 EUR DE false NEUWARE mit Rechnung und ausgewiesener MwSt. DHL Versand! Packstationen und Postfächer mög false true true false A21TN7USOBHKH0 new 51874 98 19.89 EUR 0.00 EUR DE false Vergleichen Sie bitte zur Kontrolle unsere Artikelbeschreibung: "ZyXEL NWD2205 Netzwerkada false true true true A1UQ4F1GL6W7 new 1141 94 20.10 EUR 0.00 EUR GB false ZyXEL: productName. Professionelle Verkäufer - Sorgfältige Lieferung aus England - auf u false true true true A3DWL7Z8V42IK3 new 28610 96 15.60 EUR 4.95 EUR DE false false true true true A2KMES8VWTGCHL new 2 50 17.57 EUR 3.00 EUR DE false true false true true A1YCATCVFL5J8N new 13.90 EUR 6.90 EUR DE false Neu... Originalverpackt... Rechnung mit MwSt. false true true true " } [2]=> array(4) { 

You can see the full var dump here http://aws2013.yakodo.de/getShippingPriceDE_de.php

i used foreach loop for get results from above array but no luck.i wanna show MessageId,Body like values. can any one help me with that. thank you

  • 写回答

1条回答 默认 最新

  • dongweihuan8610 2013-09-27 06:27
    关注

    You need to parse Body element because it is in XML format:

    foreach($array as $nId => $arr) {
        echo $arr['RequestId']."<br/>
    ";
        foreach($arr['Messages'] as $nId2 => $arr2) {
            echo $arr2['MessageId']."<br/>
    ";
            $xml = simplexml_load_string($arr2['Body']);
            var_dump($xml);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站