| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FirePlugins Framework |
| 4 | - * @version 1.0.4 | |
| 4 | + * @version 1.2.6 | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2026 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FPFramework\Helpers; |
| @@ -15,9 +15,36 @@ | ||
| 15 | 15 | { |
| 16 | 16 | exit; // Exit if accessed directly. |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -class ArrayHelper { | |
| 19 | +class ArrayHelper | |
| 20 | +{ | |
| 21 | + /** | |
| 22 | + * Fix arrays, remove duplicate items, null items and whitespace around item values. | |
| 23 | + * | |
| 24 | + * @param array $subject | |
| 25 | + * | |
| 26 | + * @return array The new cleaned array | |
| 27 | + */ | |
| 28 | + public static function cleanArray($subject) | |
| 29 | + { | |
| 30 | + if (!is_array($subject)) | |
| 31 | + { | |
| 32 | + return []; | |
| 33 | + } | |
| 34 | + | |
| 35 | + $subject = array_unique($subject); | |
| 36 | + $subject = array_map('trim', $subject); | |
| 37 | + | |
| 38 | + // Remove empty items. We use a custom callback here because the default behavior of array_filter removes 0 values as well. | |
| 39 | + $subject = array_filter($subject, function($value) | |
| 40 | + { | |
| 41 | + return ($value !== null && $value !== false && $value !== ''); | |
| 42 | + }); | |
| 43 | + | |
| 44 | + return $subject; | |
| 45 | + } | |
| 46 | + | |
| 20 | 47 | /** |
| 21 | 48 | * Merges 2 arrays |
| 22 | 49 | * |
| 23 | 50 | * @param array $arr1 |