Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将字符串值放入按enters分隔的数组中_Php_Arrays - Fatal编程技术网

Php 将字符串值放入按enters分隔的数组中

Php 将字符串值放入按enters分隔的数组中,php,arrays,Php,Arrays,我有一根这样的线: $str = " test1 test2 test3 test4 test5"; 我想把它变成: array('test1','test2','test3' ect ect) 我该怎么做 更具体地说,使用explode函数,使用行尾作为分隔符,然后将其包装在array_filter函数中,以从奇数行条目中删除任何杂散条目 $arr = array_filter(explode("\n", $str)); 干得好:

我有一根这样的线:

$str = "
test1
test2
test3
test4
test5";
我想把它变成:

array('test1','test2','test3' ect ect)

我该怎么做

更具体地说,使用explode函数,使用行尾作为分隔符,然后将其包装在array_filter函数中,以从奇数行条目中删除任何杂散条目

$arr = array_filter(explode("\n", $str));
干得好: