我有一个包含不同形式数据的数组。我需要一种方法来获取form_name = demographics的数组并输出它们。
我尝试了一个while循环来查找包含form_name'demographics'的数组但是我得到的结果是什么
此数组由以下人员生成:
$question_set_p1 = [];
$num_questions_set_p1 = count($choice_set_p1);
//get the keys from the choice_set array
$question_num_p1 = array_keys($choice_set_p1);
for($i = 0; $i < $num_questions_set_p1; $i++){
$question_set_p1[] = $tyler->prepQuestion($data_dictionary_p1, $choice_set_p1, $question_num_p1, $i);
}
竞争者中的数组:
[1]=>
array(11) {
["field_label"]=>
string(24) "What is your first name?"
["field_name"]=>
string(6) "f_name"
["identifier"]=>
bool(true)
["options"]=>
bool(false)
["form_name"]=>
string(12) "demographics"
}
[2]=>
array(11) {
["field_label"]=>
string(23) "What is your last name?"
["field_name"]=>
string(6) "l_name"
["identifier"]=>
bool(true)
["options"]=>
bool(false)
["form_name"]=>
string(12) "demographics"
}
[3]=>
array(11) {
["field_label"]=>
string(32) "Researcher who took measurements"
["field_name"]=>
string(17) "weight_researcher"
["identifier"]=>
bool(false)
["options"]=>
bool(false)
["form_name"]=>
string(6) "weight"
}
答案 0 :(得分:2)
要获取数据,您可以使用array_filter()
:
$data = array_filter($data, function($arr){ return $arr['form_name'] === 'demographics'; });
至于输出,这完全取决于你想要输出的格式,需要显示的数据等等,我真的不能给你一个有价值的演示。无论如何,这很简单。