2017-05-19 05:11
浏览 216


I want to get the count of each variable in an array. Am getting the object like [1,1,2,2,3,4,5,4,6]

$array = array(12,43,66,21,56,43,43,78,78,100,43,43,43,21);
$vals = array_count_values($array);

This function is the solution. But I can't make the collection object to string or array.

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

我想得到数组中每个变量的计数。 得到像[1,1, 2,2,3,4,5,4,6]

  $ array = array(12,43,66,21,56,43,43,78,78,100  ,43,43,43,21); 
 $ vals = array_count_values($ array); 

此功能是解决方案。 但我无法将集合对象变为字符串或数组。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumie6223 2017-05-19 05:18

    I noticed this is tagged with laravel, in that case you could do collect($vals)->toArray(). If I remember correctly.

    edit: you are looking for the php function implode.

    string implode ( string $glue , array $pieces )

    解决 无用
    打赏 举报

相关推荐 更多相似问题