From 99aa52b675e34facdbae0eeadb2bc05c83daed60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Cansado=20Sola=CC=80?= Date: Mon, 26 Aug 2019 12:53:42 +0200 Subject: [PATCH] Fix globalChain with number values --- src/Filter.php | 4 +++- tests/FilterTest.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 9fd9c35..872412c 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -134,7 +134,9 @@ protected function filterArrayWithGlobalChain(array $data) $data = $this->filterValueWithGlobalChain($value, $key, $data); } - return array_filter($data); + return array_filter($data, function ($value) { + return $value || is_numeric($value); + }); } /** diff --git a/tests/FilterTest.php b/tests/FilterTest.php index 2507cf5..5099905 100644 --- a/tests/FilterTest.php +++ b/tests/FilterTest.php @@ -322,8 +322,18 @@ public function testRemoveNullOnAllMultidimensionalValues() ], 'test2' => null, ], + 'test6' => '0', + 'test7' => '0.0', ]); - $this->assertEquals(['test2' => 'test', 'test4' => 'test'], $result); + $this->assertEquals( + [ + 'test2' => 'test', + 'test4' => 'test', + 'test6' => '0', + 'test7' => '0.0' + ], + $result + ); } }