function compact(array $array)
{
$newarray = $array;
foreach($newarray as $key => $value)
{
if($value == null)
{
unset($newarray[$key]);
}
}
return $newarray;
}
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] =>
[4] =>
)
function compac(array $data)
{
return array_filter($data, function($el) {
return !empty($el);
});
}
print_r(compac([0,1,2,3,null,5]));
function compac(&$data)
{
$data = array_filter($data, function($el) use ($data) {
return !empty($el);
});
}
$array = [0,1,2,3,null,5];
compac($array);
print_r( $array );