2013-03-30 63 views
0

以下代碼將XML轉換爲數組。我想通過[名字]的價值得到刺激。所以例如:$ .. [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 
       ) 
     ) 
) 

回答

0

嘗試通過所有使用PHP foreach環路項目的循環。

$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)。