對於任何人誰是尋找清潔變量,它是一個簡單的數組或多維數組這裏(未知深度嵌套數組)是我建議的解決方案: (它被創建爲一個類中的靜態函數,但也可以工作在類外部 - >只是刪除自::)
public static function clean($Array, $Strict=true)
{
if(! is_array($Array))
{
return $Array;
}
$cleaned = array();
foreach ($Array as $key => $value)
{
if($Strict)
{
if(!empty($value))
{
$tmp = self::clean($value,$Strict);
if(!empty($tmp))
{
$cleaned[$key] = $tmp;
}
}
}//strict
else
{
if(is_array($value))
{
if(!empty($value))
{
$tmp = self::clean($value,$Strict);
if(!empty($tmp))
{
$cleaned[$key] = $tmp;
}
}
}
elseif(strlen($value) > 0)
{
$tmp = self::clean($value,$Strict);
if(strlen($tmp) > 0)
{
$cleaned[$key] = $tmp;
}
}
}//not strict
} //end foreach
return $cleaned;
}
希望省時間:)乾杯
啊,魔術......謝謝瑞安:) – 2011-04-21 22:35:39