php - 在数组中添加逗号

时间:2012-08-22 23:52:53

标签: php

我有以下数组,我试图用以下代码添加逗号,但我没有得到值只显示“数组”..

数组值

Array (
[0] => Array ( 
   [0] => 144 [category_id] => 144 ) 
   [1] => Array ( [0] => 98 [category_id] => 98 ) 
   [2] => Array ( [0] => 146 [category_id] => 146 ) 
   [3] => Array ( [0] => 142 [category_id] => 142 )
)

尝试使用逗号显示值的代码

$comma_separated = implode(",", $result_array);
echo $comma_separated;

输出我

Array,Array,Array,Array

请检查我的错误

1 个答案:

答案 0 :(得分:1)

$comma_separated = implode(',', array_map(function($i) { return $i[0]; }, $result_array));
echo $comma_separated;