P粉0601123962023-08-15 09:36:30
Please try the following code
$countResult = array(); foreach( $swatchLists as $item ){ if( isset($item['type']) == false ){ continue; // 排除不包含'type'的数组 } $type = $item['type']; if( isset($countResult[$type]) ){ $countResult[$type]++; }else{ $countResult[$type] = 1; } } var_dump($countResult);
Each type of count will be stored in $countResult
, where the array key is the type value and the array value is the count.