2012-06-04 125 views
0

嗨,我需要幫助陣列創建需要在數組中刪除空值

我已經擺陣的紀錄,我不得不更換「& NBSP」空數組;

條件如果所有數組值都爲空需要從該數組中刪除行 如果行中有一個或兩個值爲空需要替換爲「& nbsp」;

我試圖刪除空值,但是同時在插入記錄扔錯誤怎麼把所有的列將不匹配所述插入條件

I,E下面我已經放置樣品數組值中,我以除去第一行怎麼把所有的值都是空的,並且在第2行中我已將空值替換爲「& nbsp」;

Array 
(
[0] => 
[1] => 
[2] => 
[3] => 
[4] => 
[5] => 
) 
Array 
(
[0] => [email protected] 
[1] => [email protected] 
[2] => 
[3] => [email protected] 
[4] => [email protected] 
[5] => [email protected] 
) 
foreach ($rows as $r) { 
$SweepedArray = array_values(array_filter($r)); 
if (!empty($SweepedArray) && $SweepedArray != "") { 
$value[] = implode(',', $r); 
} 
} 

回答

0

像這樣:

foreach ($rows as &$r) { 
    if (empty($r)) { 
     $r = ""; 
    } 
}