如何处理 CSV 导入中的关联数组?
我正在构建一个 CSV 导入,其中第一行是其他所有内容的列名称。我不想使用 $row[0]
,而是使用 $row['id']
来保持代码的可读性并使未来的开发人员更容易使用。问题是...我想不出一种有效的方法来做到这一点...
while (($current = fgetcsv($handle, 1000, "\t")) !== false) {
if ($row == 0) {
}
}
我能想到的唯一方法需要一些跑腿工作,我只想有一个简单的解决方案,干净而简单(每个开发人员的梦想,我知道)。所以我想我应该在这里发帖,看看是否有人有比我想的更好的方法......
I'm building a CSV import where the first row is the column names of everything else. Instead of having $row[0]
I'd like to use $row['id']
to keep the code readable and make it easier for future developers. The problem is... I can't think of an efficient way to do this...
while (($current = fgetcsv($handle, 1000, "\t")) !== false) {
if ($row == 0) {
}
}
The only methods I can think of require a bit of legwork and I'd like to just have a simple solution that's clean and easy (every developers dream, I know). So I thought I'd post here and see if someone had a better method than what I'm thinking...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系...刚刚在 PHP.net 上找到 array_combine ..看起来正是我所需要的,
我会删除我的问题,但我认为这对某些人来说很有用......
Nevermind... just found array_combine on PHP.net... it looks like exactly what I need
I'd delete my question but I think this would be useful for some people to know...