foreach ($data as $key => $value) {
$count = count(preg_grep("/^options(\d)+$/", array_keys(get_object_vars($value))));
echo $count; exit;
echo $count
is giving 0.
If I do print_r($value);exit;
, the $value
variable is giving this result:
Maatwebsite\Excel\Collections\CellCollection Object
(
[title:protected] =>
[items:protected] => Array
(
[question_set] => Computer Basics
[question] => Who are You ?
[options1] => RK
[options2] => KAMAL
[options3] => DPK
[options4] => NARENDRA
[marks] => 5
[negative_marks] => 1
[type] => 1
)
)
I want to calculate keys options1, options2 so on because these options are dynamic. How can I do this?