What
I've found that Filter removes an empty value from the input array after you apply any filter on it:
$filter = new Filter();
$filter->all()->trim();
$result = $filter->filter([
'one' => ' 1 ',
'zero' => ' 0 ',
'space' => ' ',
'null' => null,
'false' => false
]);
var_dump($result);
/*
[
'one' => '1'
]
*/
In this case I don't want to remove empty values (especially the ' 0 ' value), I just want to trim them. If I wanted to remove empty values I would call:
$filter
->all()
->trim()
->callback(function ($value) { return $value === '' ? null : $value; })
->removeNull();
What is expected
All the array keys are preserved:
$filter = new Filter();
$filter->all()->trim();
$result = $filter->filter([
'one' => ' 1 ',
'zero' => ' 0 ',
'space' => ' ',
'null' => null,
'false' => false
]);
var_dump($result);
/*
[
'one' => '1',
'zero' => '0',
'space' => '',
'null' => '', // or null
'false' => ''
]
*/
What
I've found that Filter removes an empty value from the input array after you apply any filter on it:
In this case I don't want to remove empty values (especially the
' 0 'value), I just want to trim them. If I wanted to remove empty values I would call:What is expected
All the array keys are preserved: