2010-12-18 62 views
0

嗨如何將此數組存儲到兩個不同的變量而不是回聲?如何將此數組存儲到多個變量?

$countries = array(); 
foreach ($my_data as $node) 
{ 
    foreach($node->getElementsByTagName('a') as $href) 
    { 
     preg_match('/([0-9\.\%]+)/',$node->nodeValue, $match); 
     $countries[trim($href->nodeValue)] = $match[0]; 
    } 
}  

foreach ($countries as $country => $percent) echo str_replace("Â","",(strip_tags($country))) . ' - ' . str_replace("Â","",(strip_tags($percent))); 

這將輸出

USA - 75% 
UK - 65% 
AU - 56% 
UAE - 52% 

等 我所尋找的,我需要這個陣列中的多個可變存儲例如

$datac = USA,UK,AU,UAE 

$datap = 75%,65%,56%,52% 

這樣的任何想法?

+0

你更換被破壞你的數據。 – 2010-12-18 04:48:07

回答

2
$datac = array(); 
$datap = array(); 

foreach($countries as $country => $percent) { 
    $datac[] = str_replace("Â","",(strip_tags($country))); 
    $datap[] = str_replace("Â","",(strip_tags($percent))); 
} 

如果你希望他們爲字符串,你可以做:

$datac = implode(',', $datac); 
$datap = implode(',', $datap); 

參考:implode

+0

費利克斯·克林你是一個高手..非常感謝你 – mathew 2010-12-18 03:45:46

相關問題