//go through each question
foreach($file_data as $value) {
//separate the string by pipes and place in variables
list($category, $question) = explode('|', $value);
//place in assoc array
$data = array($category => $question);
print_r($data);
}
这不起作用,因为它替换了数据的值。我怎样才能让它在每个循环中添加一个关联值呢? $file_data
是一个动态大小的数据数组。
原文由 Phil 发布,翻译遵循 CC BY-SA 4.0 许可协议
我想你想要
$data[$category] = $question;
或者,如果您想要一个将类别映射到问题数组的数组: