Array
(
[0] => Array
(
[0] => a
[1] => b
)
[1] => Array
(
[0] => c
)
[2] => Array
(
[0] => d
[1] => e
[2] => f
)
)
我想使用implode或php中的任何其他函数将上面的二维数组转换为以下数组
Array
(
[0]=>a,b
[1]=>c
[2]=>d,e,f
)
答案 0 :(得分:4)
您可以使用loop
和implode
来存储它们 -
foreach($yourArray as $key => $array) {
$yourArray[$key] = implode(',', $array);
}
或array_map
也有帮助 -
$new = array_map(function($array) {
return implode(',', $array);
}, $yourArray);
答案 1 :(得分:0)
$newArray = array();
foreach ($array $k => $v) {
$newArray[$k] = implode(",", $v);
}
答案 2 :(得分:0)
如果您想更改现有阵列,
$new_array = array_map('implode', $your_array,
array_fill(0, count($your_array), ',')
);
如果你想要一个新阵列,
import com.boayz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.baoyz.swipemenulistview.SwipeMenuLayout;
import com.baoyz.swipemenulistview.SwipeMenuListView;
import com.baoyz.swipemenulistview.SwipeMenuListView.OnMenuItemClickListener;
import com.baoyz.swipemenulistview.SwipeMenuListView.OnSwipeListener;