From bd09c30efc89c263d0f4f7d8807b613d3b224070 Mon Sep 17 00:00:00 2001 From: ecoreng Date: Thu, 31 Jul 2014 22:55:20 -0700 Subject: [PATCH] refactor to avoid foreach when filtering --- src/Valitron/Validator.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index b9b4e41..746a179 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -78,11 +78,7 @@ class Validator { // Allows filtering of used input fields against optional second array of field names allowed // This is useful for limiting raw $_POST or $_GET data to only known fields - foreach ($data as $field => $value) { - if (empty($fields) || (!empty($fields) && in_array($field, $fields))) { - $this->_fields[$field] = $value; - } - } + $this->_fields = !empty($fields) ? array_intersect_key($data, array_flip($fields)) : $data; // set lang in the follow order: constructor param, static::$_lang, default to en $lang = $lang ?: static::lang();