1. 程式人生 > >array_filter,可以應用於賦值

array_filter,可以應用於賦值

$model->attributes = array_filter(Yii::$app->request->post()
<?php 
$arr=array(0,'linux',123,'hello',false,array(),'0');

$rst=array_filter($arr);

echo '<pre>';
print_r($rst);
echo '</pre>';
//輸出的結果是:
/*
Array
(
    [1] => linux
    [2] => 123
    [3] => hello
)
 */
//用於賦值的時候,清除前端轉過來的表單中的空值
 ?>