数组内部的数组,只接受传入的数组

时间:2013-02-25 16:21:26

标签: php arrays

我有以下数组结构,这是传入$ response

的数组

阵列

(
    [inbox] => Array
        (
            [0] => Array
                (
                    [location] => 3
                    [ID] => 8ba84195fe79a89af1a4b5bd8c280621
                    [smsc_number] => +44******
                    [sent] => 2013-02-25 14:57:20
                    [coding] => Default GSM alphabet (no compression)
                    [remote_number] => +447****
                    [status] => Read
                    [body] => Yeppp
                )

        )

    [outbox] => Array
        (
            [0] => Array
                (
                    [location] => 2
                    [ID] => d22c4368fadd64e98fab64acb6b8fa34
                    [reference_number] => 1
                    [class] => 1
                    [coding] => Default GSM alphabet (no compression)
                    [remote_number] => *****
                    [status] => Sent
                    [body] => Test
                )

            [1] => Array
                (
                    [location] => 0
                    [ID] => f0c05e8dd2578d16d73bf5dbcf2ec3e6
                    [class] => 1
                    [coding] => Default GSM alphabet (no compression)
                    [remote_number] => 0****
                    [status] => UnSent
                    [body] => fdgg ddfgfdg fd
                )

            [2] => Array
                (
                    [location] => 1
                    [ID] => d7537acb1b3994ecc11369bac46c4bb6
                    [class] => 1
                    [coding] => Default GSM alphabet (no compression)
                    [remote_number] => 0****3
                    [status] => UnSent
                    [body] => fdgg ddfgfdg fd
                )

        )

)

我只对收件箱数组的主体感兴趣。我以为我可以做两个循环来获得这个,或者只是做$ response [0]但它似乎不起作用。继承人我所拥有的:

$response = $sms->Get();

foreach ($response[0] as $value) {
    foreach ($response as $value1) {
       echo($value1['body']); 
}

}

我显然做了一些非常愚蠢的事情 - 任何帮助都会非常感激

1 个答案:

答案 0 :(得分:0)

试试这个

foreach ($response['inbox'] as $inb) {    
   echo($inb['body']); }