PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.14
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Framework / Inc / Helpers / ArrayHelper.php

ArrayHelper.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.14, at Inc/Framework/Inc/Helpers/ArrayHelper.php

129 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FirePlugins Framework
4 * @version 1.1.102
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FPFramework\Helpers;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
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 $subject;
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
47 /**
48 * Merges 2 arrays
49 *
50 * @param array $arr1
51 * @param array $arr2
52 *
53 * @return return
54 */
55 public static function arrayMerge($arr1, $arr2)
56 {
57 $new_arr = $arr1;
58
59 foreach ($arr2 as $key => $value)
60 {
61 if (isset($new_arr[$key]) && is_array($new_arr[$key]) && is_array($value))
62 {
63 $tmp = array_unique(array_merge($new_arr[$key], $value));
64 $new_arr[$key] = $tmp;
65 }
66 else
67 {
68 $new_arr[$key] = $value;
69 }
70 }
71
72 return $new_arr;
73 }
74
75 /**
76 * Method to determine if an array is an associative array.
77 *
78 * @param array $array An array to test.
79 *
80 * @return boolean
81 */
82 public static function isAssociative($array)
83 {
84 if (\is_array($array))
85 {
86 foreach (array_keys($array) as $k => $v)
87 {
88 if ($k !== $v)
89 {
90 return true;
91 }
92 }
93 }
94
95 return false;
96 }
97
98 /**
99 * Inserts value after given key.
100 *
101 * @param array $input The input where we will search and add the new $element
102 * @param mixed $index The index that we use to find the key and insert after
103 * @param mixed $newKey The new index that will be used for this key, value pair
104 * @param mixed $newValue The new value of the key, value pair
105 *
106 * @return array
107 */
108 public static function insertAfter($input, $index, $newKey, $newValue)
109 {
110 if (!array_key_exists($index, $input))
111 {
112 throw new \Exception('Index not found');
113 }
114
115 $tmpArray = [];
116
117 foreach ($input as $key => $value)
118 {
119 $tmpArray[$key] = $value;
120
121 if ($key === $index)
122 {
123 $tmpArray[$newKey] = $newValue;
124 }
125 }
126
127 return $tmpArray;
128 }
129 }