0

以下代码将 XML 转换为数组。我想通过 [name] 的值得到一个刺痛。所以例如: $..[offerid].. 应该给 8b5f7fd3806a42ccb0ade9f8309c5587 谁能帮帮我?:)

$xmldata = file_get_contents($XMLURL);
$arr= xml2ary($xmldata);

foreach($arr['m4n']['_c']['data']['_c']['record'] as $result){
echo "<pre>"; print_r($result);
}

回显结果为:

Array
(
    [recordHash] => Array
        (
            [_v] => -652572603
        )

    [column] => Array
        (
            [0] => Array
                (
                    [_a] => Array
                        (
                            [name] => url
                        )

                    [_v] => http://ad.dd.com/ppc/?20910868C187884459&zpar6=DF_1&ULP=[[http%3A%2F%2F]]
                )

            [1] => Array
                (
                    [_a] => Array
                        (
                            [name] => title
                        )

                    [_v] => This is the title
                )

            [2] => Array
                (
                    [_a] => Array
                        (
                            [name] => description
                        )

                    [_v] => Aanbod
                )

            [3] => Array
                (
                    [_a] => Array
                        (
                            [name] => offerid
                        )

                    [_v] => 8b5f7fd3806a42ccb0ade9f8309c5587
                )
        )
)
4

1 回答 1

0

尝试使用 phpforeach循环遍历所有项目。

$name_to_find = 'offerid';
$value = FALSE;

foreach ($result['column'] as $item) {
  if ($item['_a']['name'] == $name_to_find) {
    $value = $item['_v'];
    break;
  }
}

// Now $value has the value of the entry with the name $name_to_find

如果您最终找到了给定的条目$name_to_find,那么$value将不会FALSE(当然,您没有任何FALSE值:D)。

于 2013-03-30T02:27:00.630 回答