[英]How do I store this array to multiple variables?
Hi how do I store this array to two different variables instead of echo?? 嗨,我如何将这个数组存储到两个不同的变量而不是echo?
$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)));
This will output 这将输出
USA - 75%
UK - 65%
AU - 56%
UAE - 52%
and so on What I am looking is I need this array to store in multiple variable for example 我正在寻找的是我需要将这个数组存储在多个变量中
$datac = USA,UK,AU,UAE
$datap = 75%,65%,56%,52%
like that any idea? 那样的想法吗?
$datac = array();
$datap = array();
foreach($countries as $country => $percent) {
$datac[] = str_replace("Â","",(strip_tags($country)));
$datap[] = str_replace("Â","",(strip_tags($percent)));
}
If you want them as strings, you can just do: 如果希望将它们作为字符串,则可以执行以下操作:
$datac = implode(',', $datac);
$datap = implode(',', $datap);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.