drqvsx1228
2012-08-22 23:52
浏览 128
已采纳

php - 在数组中添加逗号

i have following array, and i have tried to add comma with the following code but i am not getting values its shows "array" only..

Array Value

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 )
)

Tried code to display values with commas

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

output i am getting

Array,Array,Array,Array

please check what i am getting wrong

图片转代码服务由CSDN问答提供 功能建议

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

数组值

 数组(
 [0] => 数组(
 [0] => 144 [category_id] => 144)
 [1] =>数组([0] => 98 [category_id] => 98)
 [2] =  >数组([0] => 146 [category_id] => 146)
 [3] =>数组([0] => 142 [category_id] => 142)
)
 <  / code>  
 
 

尝试用逗号显示值的代码

  $ comma_separated = implode(“,”  ,$ result_array); 
echo $ comma_separated; 
   
 
 

输出我

 <  code> Array,Array,Array,Array 
   
 
 

请检查我的错误

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duancashi1362 2012-08-22 23:55
    已采纳
    $comma_separated = implode(',', array_map(function($i) { return $i[0]; }, $result_array));
    echo $comma_separated;
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题