求解數組的列數
P粉818317410
2023-08-14 11:01:59
<p>在這個陣列輸出中,我如何計算類型的數量?或者更好的是,如何在計算時排除additional_data? </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>嘗試過
<code>count(array_column($swatchLists, 'type'));</code></p>
<p>但輸出為0</p>
請嘗試以下程式碼
每種類型的計數都會儲存在
$countResult
中,陣列鍵是類型值,陣列值是計數。