Joa*_*Sjo 3 php arrays predicate count
我有这个数组:
Array
(
[boks_1] => Array
(
[tittel] => Test
[innhold] => This is a test text
[publish] => 2
)
[boks_2] => Array
(
[tittel] => Test 3
[innhold] => This is a text test
[publish] => 1
)
[boks_3] => Array
(
[tittel] => Kontakt oss
[innhold] => This is a test text
[publish] => 1
)
)
Run Code Online (Sandbox Code Playgroud)
如何使用PHP count()计算[publish] => 1我的数组中出现的次数?我将使用该值来控制divsFlexbox容器中的宽度.
为了娱乐:
$count = array_count_values(array_column($array, 'publish'))[1];
Run Code Online (Sandbox Code Playgroud)
publish密钥1使用索引获取s 的计数[1]好的更有趣:
$count = count(array_keys(array_column($array, 'publish'), 1));
Run Code Online (Sandbox Code Playgroud)
publish密钥1注意:您可能希望true作为第三个参数传递为array_keys()更准确并使用'1'而不是1如果1s是字符串而不是整数.
| 归档时间: |
|
| 查看次数: |
73 次 |
| 最近记录: |