В настоящее время я работаю над чтением папки, в которой находятся все мои файлы .txt, затем читаю данные всех файлов и сохраняю их в базе данных. Это мой код для того, чтобы взять все данные из файла и проанализировать их в массив:
<code>/**
*
* @param array $paths [files/8754D394_20200219131722_oplog.txt]
* @param string $file_name [8754D394_20200219131722]
* @param string $file_name [8754D394_20200219131722]
* @param array $explodes [[1 => 8754D394, 2 => 20200219131722]]
*/
public function index()
{
$paths = glob('files/*.txt');
foreach ($paths as $key =>$path) {
// files name and storing it to array
$file_name = basename($path, '_oplog.txt');
$explodes = explode( '_', $file_name );
$data_file = array();
$data_file[$key] = $explodes;
// Date
$full_date = substr($data_file[$key][1], 0, -6);
$years = substr($full_date, 0, -4) . '-';
$months = substr($full_date, 4, -2) . '-';
$days = substr($full_date, 6);
$full_date = $years . $months . $days;
// storing data to database
$fileDatabase = new File();
$fileDatabase->name = $file_name;
$fileDatabase->vei_id = $data_file[$key][0];
$fileDatabase->file_date = $full_date;
// $fileDatabase->save();
$content = file_get_contents($path);
$content = str_replace(array("\n", "\r"), '', $content);
$content = explode(';', $content);
unset($content[count($content) - 1]);
$data_content = array();
$data_content[$key] = $content;
foreach ($data_content[$key] as $row) {
if($row == '\n') {
$data_content[] = $row;
}
}
echo "<pre>";
print_r($data_content);
echo "
";}}
Проблема в том, что мне нужно, чтобы мой массив выглядел так :
file1.txt
Array
(
[0] => Array
(
[0] => 19/02/2020 12:17:05
[1] => OBD
[2] => SetSpeedLimit
[3] => FR
[4] => HW3
[5] =>
)
[1] => Array
(
[0] => 19/02/2020 12:17:05
[1] => OBD
[2] => SetSpeedLimit
[3] => FR
[4] => HW3
[5] =>
)
)
file2.txt
Array
(
[0] => Array
(
[0] => 19/02/2020 12:17:05
[1] => OBD
[2] => SetSpeedLimit
[3] => FR
[4] => HW3
[5] =>
)
)
file3.txt
Array
(
[0] => Array
(
[0] => 19/02/2020 12:17:05
[1] => OBD
[2] => SetSpeedLimit
[3] => FR
[4] => HW3
[5] =>
)
[1] => Array
(
[0] => 19/02/2020 12:17:05
[1] => OBD
[2] => SetSpeedLimit
[3] => FR
[4] => HW3
[5] =>
)
[2] => Array
(
[0] => 19/02/2020 12:17:05
[1] => OBD
[2] => SetSpeedLimit
[3] => FR
[4] => HW3
[5] =>
)
)
и так далее ...
Но я получаю вот так:
[1] => Array
(
[0] => 25/01/2020 08:57:53
[1] => OBD
[2] => FLASHWrite
[3] => MR
[4] => A7
[5] =>
[6] => 25/01/2020 09:08:58
[7] => OBD
[8] => FLASHWrite
[9] => MR
[10] => A7
[11] =>
[12] => 25/01/2020 09:16:39
[13] => OBD
[14] => FLASHWrite
[15] => MR
[16] => A7
[17] =>
[18] => 25/01/2020 10:48:45
[19] => OBD
[20] => FLASHWrite
[21] => MR
[22] => A7
[23] =>
)
)
Буду очень благодарен за любую помощь.