0

这是数组结构(仅数组中的第一个元素):

Array
(
    [1] => Array
        (
            [pageid] => 1
            [step_order] => 1
            [pageurl] => http://www.domain.com/
            [in_links] => Array
                (
                    [domains] => Array
                        (
                            [Direct Entry] => 1520
                            [www.google.com] => 387
                            [www.google.co.in] => 14
                            [search.yahoo.com] => 10
                            [All other] => 27
                        )

                    [impressions] => Array
                        (
                            [Direct Entry] => Array
                                (
                                    [0] => 10654
                                    [1] => 10728
                                    [2] => 10772
                                )

                            [www.google.com] => Array
                                (
                                    [0] => 10991
                                    [1] => 12455
                                    [2] => 12466
                                    [3] => 10757
                                )

                            [www.google.co.in] => Array
                                (
                                    [0] => 9839
                                    [1] => 9837
                                    [2] => 9845
                                )

                            [search.yahoo.com] => Array
                                (
                                    [0] => 12087
                                    [1] => 10864
                                )

                        )

                )

            [out_links] => Array
                (
                    [domain] => Array
                        (
                            [Left site] => 1752
                            [http://www.domain.com/#] => 102
                            [http://www.domain.com/contact] => 102
                            [http://www.domain.com/#basic_inline_div] => 2
                        )

                    [impressions] => Array
                        (
                            [Left site] => Array
                                (
                                    [0] => 7680
                                    [1] => 9728
                                    [2] => 10496
                                )

                            [http://www.domain.com/#] => Array
                                (
                                    [0] => 259
                                    [1] => 11013
                                )

                            [http://www.domain.com/contact] => Array
                                (
                                    [0] => 12802
                                    [1] => 10757
                                )

                            [http://www.domain.com/#basic_inline_div] => Array
                                (
                                    [0] => 11
                                    [1] => 51
                                )

                        )

                )

            [visitors] => 1958
        )
)

我正在尝试循环从域、印象(和子元素)中获取元素。我设法得到了第一部分:pageid、step_order、page_url。我在使用 in_links 和 out_links 及其子数组时遇到问题。有人对如何提取这些数据有想法吗?

4

1 回答 1

1

以下是您从 in_links 获取域的方法。其他类似(但我不确定印象子数组中的索引代表什么)。

foreach ($array as $element) {
  foreach ($element['in_links']['domains'] as $domain => $count) {
    echo "Domain: $domain, Count: $count\n";
  }
}
于 2013-03-14T17:40:59.540 回答