Php – Count multidimensional complex array values

  arrays, count, iteration, multidimensional-array, php

Have to count number of questions (questions_row_id)

  • evaluator wise and settings wise

From the following array:

array:3 [▼
  0 => array:1 [▼
    0 => array:3 [▼
      "questions_row_id" => 1
      "settings_row_id" => 1
      "evaluator_row_id" => array:3 [▼
        0 => "1"
        1 => "4"
        2 => "101"
      ]
    ]
  ]
  1 => array:1 [▼
    0 => array:3 [▼
      "questions_row_id" => 2
      "settings_row_id" => 1
      "evaluator_row_id" => array:2 [▼
        0 => "1"
        1 => "100"
      ]
    ]
  ]
  2 => array:1 [▼
    0 => array:3 [▼
      "questions_row_id" => 4
      "settings_row_id" => 3
      "evaluator_row_id" => array:2 [▼
        0 => "1"
        1 => "101"
      ]
    ]
  ]
]

What I am looking for:

For (Evaluator id == 1 and settings id == 1) number of questions = 2

and again
for (Evaluator id == 1 and settings id == 3) number of questions = 1

Need some hints on how to approach this and if possible any working samples are also appreciated.

Source: Ask PHP

LEAVE A COMMENT