Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to count same value comma separated string in php

by
Category:php
php mysql
How to count same value comma separated string in php

If you want to get duplicate values count in an comma separated string in php, first need to create array using explode function.

Many time user ask me how to count duplicate value comma separated string in Laravel 5.

The array_count_values() function counts all the values of an array.

$colorstring = 'A,A,B,C,D,A,B';
$colordata = explode(',', $colorstring);
$vals = array_count_values($colordata);

Output

Array ( [A] => 3 [B] => 2 [C] => 1 [D] => 1 ) 

0 Comments


Html code work in comment box


Related Post