2011-04-11 71 views
-3

我想返回这个数组的'message-> text'部分。你可以帮我吗?我在这方面遇到了一些困难。帮忙遍历数组php

Array (
    [name] => new exp 
    [created] => Array (
     [date] => 20110304 
     [time] => 11:09:27 
     [version] => 2.02.6 
    ) 
    [message] => Array (
     [0] => Array (
      [@attributes] => Array (
       [id] => 0 [mbox] => recipe 
      ) 
      [received] => Array (
       [date] => 20090304 
       [time] => 13:16:48 
      ) 
      [from] => Array (
       [name] => Andrew Welch 
       [email] => <email address removed> 
      ) 
      [to] => Array (
       [name] => <email address removed> 
       [email] => <email address removed> 
      ) 
      [messageid] => <email address removed> 
      [subject] => aloo paranthas 
      [text] => you take potatoes ... to cook. 
      [attachment] => Array (
       [name] => part-003.html 
       [dir] => page0001/000000 
       [bytes] => 864 
       [size] => 864.00 B 
       [type] => text/html 
      ) 
      [mboxname] => recipe 
     ) 
     [1] => Array (
      ... 
+0

甚至不关心正确地格式化阵列并将其减少到最不需要的问题信息? – 2011-04-11 12:58:52

+0

不完整的数组。 – kjy112 2011-04-11 12:59:34

+0

'@ attributes'表明这是/是一个SimpleXml结构。 – Gordon 2011-04-11 13:14:31

回答

3

的阵列结构是像这样:

Array (
    ... 
    [message] => Array (
     [0] => Array (
      ... 
      [text] => you take potatoes ... to cook. 
      ... 
     ) 
     [1] => Array (
      ... 
     ) 
     ... 
    ) 
) 

所以$data['message']本身是一个数组:

for($i = 0, $l = count($data['message']); $i < $l ; $i++) { 
    echo $data['message'][$i]['text']; 
} 

我建议阅读有关arrays in PHP

+0

谢谢你。 – weaveoftheride 2011-04-11 13:34:52