dougan7657
2015-09-23 22:25如何将文件转换为关联数组? 并使用前3个字符作为键
I have a file like below, which I need to convert into an array:
ABCLine, Number, One DEFNumber, Two, Line GHIThree, Line, Number
I can get each line and turn it into a value of an array, but what I need to do is take the first 3 characters and turn that into a key and then the rest of the line into the value.
So my expected array would be:
Keys | Values
----------------------------
ABC | Line, Number, One
DEF | Number, Two, Line
GHI | Three, Line, Number
I honestly am not too sure where to begin, I've been looking all over and haven't been able to find a way to just take those first 3 characters and turn those into a key for the remainder of the line.
I started with some code, which looks like this:
<?php
echo "Name<br/>";
$file = "hw3.txt";
$f1 = fopen($file, 'r');
$array = array();
?>
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- 将字符串转换为关联数组,或者将数组转换为关联数组
- converter
- string
- arrays
- php
- 1个回答
- 我想将字符串(关联数组字符串)转换为关联数组?
- arrays
- php
- 5个回答
- 在PHP中将字符串转换为关联数组
- json
- arrays
- php
- 3个回答
- 如何将文件转换为关联数组? 并使用前3个字符作为键
- file
- arrays
- php
- 2个回答
- 将字符串转换为关联数组
- arrays
- php
- 1个回答
换一换