【问题标题】:Merge Arry for sitemap & implode合并 Arry 以获取站点地图和内爆
【发布时间】:2022-01-02 02:46:54
【问题描述】:

我使用 implode '/' 但在这种情况下, 我想要,最后两列iid & branch_id like ==>>>> iid."_".branch_id 我的意思是最后两列内爆将是'_'下划线而不是'/'斜线,但对于前4列'将是/,仅对于最后两列,它将是下划线。请帮助我找到正确的解决方案。谢谢

echo "Creating Sitemap\n";
$switzerland= new Sitemap($switzerlandcodes_sitefile,["name","canton","city","iid","branch_id"],"UNKNOWN", $homeUrl.SWITZERLANDPATH.'/', SWITZERLANDTABLE);
$switzerland->createSitemap();
$files=array_merge($files,$switzerland->files);

【问题讨论】:

    标签: php mysql arrays sitemap array-merge


    【解决方案1】:

    在示例中,您没有向我们展示您的数据您如何使用 implode 函数,而是基于您的问题文本,我会这样说:

    • array_chunk 按长度为 3 (name, canton, city) split 数组为 base 数组和 param 数组
    • implode base by /
    • implode param by _
    • 将其与/ 连接在一起
    $data = ['SomeName', 'Canton', 'AnotherCity', 'SomeIID', 'SomeBranchID'];
    [$base, $param] = array_chunk($data, 3);
    $result = implode('/',$base).'/'.implode('_',$param);
    

    结果是

    SomeName/Canton/AnotherCity/SomeIID_SomeBranchID
    

    【讨论】:

      猜你喜欢
      • 2022-12-06
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多