2

I have a Laravel Collection value returned below:

image

My question is how to count the total no. of data contained each. Like the example above I must have a result value of 9 with that example.

I tried the below code:

array_count_values($jobs)

But as expected it returns an error:

array_count_values() expects parameter 1 to be array, object given


Someone knows how to achieve this either in native php way or laravel collection methods?
schutte
  • 1,949
  • 7
  • 25
  • 45

1 Answers1

3

If You have Collection instance you can use

$jobs->collapse()->count()

Davit Zeynalyan
  • 8,418
  • 5
  • 30
  • 55