Count a specific value from PHP array

  arrays, php

I managed this code to get the count of specific value inside the array
It works fine, but Is there a better way to simplify it?

$array= '[
{"s":1},
{"s":1},
{"s":2},
{"s":5}
]';

$json=json_decode($array);
 $count1=0;
 $count2=0;
$count5=0;
        foreach( $json as $j ) { 
          if($j->s===1){
            $count1++;
          };
  if($j->s===2){
            $count2++;
          };
  if($j->s===5){
            $count5++;
          };

        }
        echo $count1; // 2
echo $count2; // 1
echo $count5; // 1

Source: Ask PHP

LEAVE A COMMENT