dongqing4774 2010-12-18 03:39
浏览 42
已采纳

如何将此数组存储到多个变量?

Hi how do I store this array to two different variables instead of 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?

  • 写回答

1条回答 默认 最新

  • dounieliang4712 2010-12-18 03:40
    关注
    $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);
    

    Reference: implode

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 hexo+github部署博客
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?