PHP txt 一行到新数组

PHP txt a line to new array

PPP TXT:
123 45678 8888 
123 45678 8888
123 45678 8888

$file = file('PPP.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($file as $line) {
$words = explode(" ", $line);
print_r($words);
}

输出数组:

Array ( 
    [0] => 123 
    [1] => 45678 
    [2] => 8888 
) 
Array ( 
    [0] => 123 
    [1] => 45678 
    [2] => 8888 
) 
Array ( 
    [0] => 123 
    [1] => 45678 
    [2] => 8888 
)

但我想要输出数组

Array [0] ( 
    [0] => 123 
    [1] => 45678 
    [2] => 8888 
) 
Array[1] ( 
    [0] => 123 
    [1] => 45678 
    [2] => 8888 
) 
Array[3] ( 
    [0] => 123 
    [1] => 45678 
    [2] => 8888 
)

谢谢。

如果您想将它们存储为多维数组,请将每一行推入一个数组而不是单独的变量。

$file = file('PPP.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

// Instantiate the array we will store each result in
$words = [];

foreach ($file as $line) {
    // Push the result into the array
    $words[] = explode(" ", $line);
}

// Dump the array after the loop to get all of them
print_r($words);