php对数组的操作已经很完善了,提供给我们很多内置函数用以操作数组,其实可以用array_filter函数对PHP数组中的控制进行过滤 array_filter() 函数用回调函数过滤数组中的值.该函数把输入数组中的每个键值传给回调函数.如果回调函数返回 true,则把输入数组中的当前键值返回结果数组中.数组键名保持不变 其中有个小关键点:If no callback is supplied, all entries of input equal to FALSE (see converting…
手册查询array_filter()的使用细节时,看到了:If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed. 如果没有给出回调函数,所有的等于 FALSE 的元素将会被移除掉! 刚好可以用来移除数组中的空元素! 使用:$arr = array_filter($arr); <?php $arr=array(1,2,3,null,'',…
http://ruby-doc.org/core-2.2.0/Array.html#method-i-compact compact → new_aryclick to toggle source Returns a copy of self with all nil elements removed. [ "a", nil, "b", nil, "c", nil ].compact #=> [ "a", "b…