相关疑难解决方法(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万
查看次数

标签 统计

counting ×1

multidimensional-array ×1

php ×1