Kayal Kayal -4 years ago 135
PHP Question

Convert the collection object to string or array in php

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.

Answer Source

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 )

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download