foreach ($data as $key => $value) {
$count = count(preg_grep("/^options(\d)+$/", array_keys(get_object_vars($value))));
echo $count; exit;
echo $count
给出了0.
如果我print_r($value);exit;
,则$value
变量会给出此结果:
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
)
)
我想计算键选项1,选项2等,因为这些选项是动态的。我怎么能这样做?