[英]How to use CSV column as key in a multidimensional array?
Right now I'm using PHPSpreadsheets to load a CSV into a multidimensional array with a lot of for loops
. 现在,我正在使用PHPSpreadsheets将CSV加载到具有很多
for loops
的多维数组中。 In the CSV file a new row starts with what the data next to it stands for. 在CSV文件中,新行从其旁边代表的数据开始。
Is there a way to use those cells as keys in the array? 有没有办法使用这些单元格作为数组中的键? Right now the code is not dynamic at all and I want to change that.
现在,代码根本不是动态的,我想更改它。
Question 1.1 Example One : 2 : 3 : 4
Question 1.1 Example Two : 2 : 3 : 4
Question 1.1 Example Three : 2 : 3 : 4
Like that. 像那样。 I need Question 1.1 to be the key.
我需要问题1.1作为关键。
for( $x = 'B', $vragenTellen = 2; $x <= $highestColumn; $x++, $vragenTellen++){
${"competentie111vraag$vragenTellen"}= $spreadsheet1->getActiveSheet()->RangeToArray(
''.$x.'2'.':'.$x.$highestColumnForQuestions.'',
NULL,
FALSE,
TRUE,
TRUE
);
}
This is what I have right now to load in the rows with data. 这就是我现在要在数据行中加载的内容。 But I can't think of a way to connect the rows with the corresponding name.
但是我想不出一种方法来连接具有相应名称的行。 Does anyone know how to do this?
有谁知道如何做到这一点?
The way I solved my issue was by taking the code I put up in my question and telling it to only take the column that has the questions, turning it into an array. 解决问题的方法是采用问题中提出的代码,并告诉它仅采用存在问题的列,然后将其转换为数组。
Then later I created a for loop
and used the question-array as the filler for the $keys
. 然后,我创建了一个
for loop
,并将问题数组用作$keys
的填充$keys
。 This way my multi-dimensional array has all the questions and answers that go with it. 这样,我的多维数组就具有所有随之而来的问题和答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.