php在二维数组上爆炸

时间:2022-03-29 21:36:49

I have a two dimensional array in php and I want to get the second dimension (index 1) as a list of values seperated by a comma. Do I have to write my own custom functions or can I use some variation of explode on two dimensional arrays?

我在php中有一个二维数组,我希望将第二个维度(索引1)作为由逗号分隔的值列表。我是否必须编写自己的自定义函数,还是可以在二维数组上使用某些爆炸变体?

2 个解决方案

#1


1  

First of all, your are looking for implode() and not for explode().

首先,你正在寻找implode()而不是爆炸()。

function flatten($two_dim_array)
{
     $result = array();
     foreach ($two_dim_array as $array)
          $result[] = implode("," $array);
     return $result;
}

#2


3  

Depending on how your array is organized, you could do

根据阵列的组织方式,您可以这样做

x = implode(',',$two_dimensional_array['index1']);

#1


1  

First of all, your are looking for implode() and not for explode().

首先,你正在寻找implode()而不是爆炸()。

function flatten($two_dim_array)
{
     $result = array();
     foreach ($two_dim_array as $array)
          $result[] = implode("," $array);
     return $result;
}

#2


3  

Depending on how your array is organized, you could do

根据阵列的组织方式,您可以这样做

x = implode(',',$two_dimensional_array['index1']);