放大php数组

时间:2019-06-20 15:05:00

标签: php arrays

我有一个像这样的数组:

$Array = [
       [1, 33, 55, 18],
       [8, 9, 12, 67],
       [3, 33, 76, 88],
  ];

我想添加;来像这样输出:

1, 33, 55, 18; 
8, 9, 12, 67; 
3, 33, 76, 88

有人知道该怎么做吗?

1 个答案:

答案 0 :(得分:2)

使用数组映射来实现这一目标

declare module
  'country-code-lookup';

Ansible: Attach role to user in postgres

一个弯针:

$temp = array_map(function($item){
    return implode(", ", $item);
}, $Array);
foreach($temp as $v){
    // implode with ';' and \n for line break
    // you can use "<br/>" if you are using web.
    echo $v.";\n"; 
}

Demo

输出

foreach($Array as $v){
    echo implode(", ",$v).";\n";
}