最新消息: 新版网站上线了!!!

php把每次的内容转为数组

<?php
$string
="test
test2
test3
test4
test5";
$str = '';
foreach(explode("\n",$string) as $key) {
    $str .='\''.trim($key).'\',';
}
$array = explode(',',$str);
echo "<pre>";
print_r($array);
echo "</pre>";
foreach($array as $value) {
    if(!empty($value)) {
        //结果 处理
    }
 
}
/***
结果
Array
(
    [0] => 'test'
    [1] => 'test2'
    [2] => 'test3'
    [3] => 'test4'
    [4] => 'test5'
)
 
 
 
***/

转载请注明:谷谷点程序 » php把每次的内容转为数组