如何删除没有数据或为空的下一行?

问题描述 投票:1回答:4

我使用laravel删除下一行空数据时遇到问题。我哪里做错了?

我尝试使用此代码explode,str_replace和array_map,但我仍然没有得到我想要的。

$string = str_replace(array("\r", "\n"), "\n", $tempData[0]);
$your_arrays = array_map("trim", explode("\n", $string));

print_r ($your_arrays);

Array
(
    [0] => 
    [1] => 
    [2] => Sample Text1
    [3] => 
    [4] => Sample text 2
    [5] => Sample Text 3
    [6] => 
    [7] => 
    [8] => Sample Text 4
    [9] => Sample Text 5
    [10] => Sample Text 6
    [11] => Sample Text 7
    [12] => Sample Text 8
    [13] => 
    [14] => 
    [15] => 
)

我期待着这个结果

Array
(
    [1] => Sample Text1
    [2] => Sample text 2
    [3] => Sample Text 3
    [4] => Sample Text 4
    [5] => Sample Text 5
    [6] => Sample Text 6
    [7] => Sample Text 7
    [8] => Sample Text 8
)
php arrays laravel
4个回答
© www.soinside.com 2019 - 2024. All rights reserved.