Find the number of columns in an array
P粉818317410
2023-08-14 11:01:59
<p>How do I count the number of types in this array output? Or better yet, how to exclude additional_data when calculating? </p>
<pre class="brush:php;toolbar:false;">Array (
[124] =>
Array (
[type] => 0
[value] => 4 Pack
[label] => 4 Pack
)
[125] =>
Array (
[type] => 0
[value] => 6 Pack
[label] => 6 Pack
)
[126] =>
Array (
[type] => 0
[value] => 12 Pack
[label] => 12 Pack
)
[additional_data] => {"swatch_input_type":"text","update_product_preview_image":"1","use_product_image_for_swatch":0} )</pre>
<p>Tried
<code>count(array_column($swatchLists, 'type'));</code></p>
<p>But the output is 0</p>
Please try the following code
Each type of count will be stored in
$countResult
, where the array key is the type value and the array value is the count.