相关疑难解决方法(0)

计算多维数组中的特定值

我试图根据条件计算某个值出现在多维数组中的次数.这是一个示例数组;

$fruit = array (
                 "oranges" => array(
                                    "name"    => "Orange",
                                    "color"   => "orange",
                                    "taste"   => "sweet",
                                    "healthy" => "yes"
                              ),
                 "apples" => array(
                                    "name"    => "Apple",
                                    "color"   => "green",
                                    "taste"   => "sweet",
                                    "healthy" => "yes"
                              ),
                 "bananas" => array(
                                    "name"    => "Banana",
                                    "color"   => "yellow",
                                    "taste"   => "sweet",
                                    "healthy" => "yes"
                              ),
                 "grapes" => array(
                                    "name"    => "Grape",
                                    "color"   => "green",
                                    "taste"   => "sweet",
                                    "healthy" => "yes"
                              )
            );
Run Code Online (Sandbox Code Playgroud)

如果我想要显示所有绿色水果,我可以做以下(让我知道这是否是最好的方式);

for ($row = 0; $row < 3; $row++) { …
Run Code Online (Sandbox Code Playgroud)

php counting multidimensional-array

8
推荐指数
3
解决办法
2万
查看次数

php数组中的echo如何计算每个值

如何在php数组中回显每个值的计数?例如在这个数组中:

 $array = array(test,test,ok,test,ok); 
Run Code Online (Sandbox Code Playgroud)

现在怎样才能在这个数组中进行echo count测试或ok?

php arrays

2
推荐指数
1
解决办法
778
查看次数

标签 统计

php ×2

arrays ×1

counting ×1

multidimensional-array ×1