本文介绍了用逗号放大或加入多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经数组多维了。.
Array (
[123] => Array ( [0] => 120 [1] => 200 [2] => 180 [3] => 130 )
[124] => Array ( [0] => 150 [1] => 155 [2] => 160 [3] => 165 )
[125] => Array ( [0] => 121 [1] => 120 [2] => 121 [3] => 121 )
)
我要这样转换
120,200,180,130
150,155,160,165
121,120,121,121
如何编码这些家伙?
我的代码也来自stackoverflow ..
my code from stackoverflow too ..
echo join("','", array_map(function ($data) { return $data[0]; }, $data))
但是..输出
120,150,121
..我想从123
but .. the output120, 150, 121
.. i want to get from 123
推荐答案
这应该对您有用:
(这里我只是使用和并打印)
(Here I just go through each innerArray with array_map()
and implode()
it and print it)
<?php
$arr = [
"123" => [120, 200, 180, 130],
"124" => [150, 155, 160, 165],
"125" => [121, 120, 121, 121]
];
array_map(function($v){
echo implode(",", $v) . "<br />";
}, $arr);
?>
输出:
120,200,180,130
150,155,160,165
121,120,121,121
这篇关于用逗号放大或加入多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!