PluginProbe
WP Ultimate Post Grid / 2.0
WP Ultimate Post Grid v2.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / vendor / vafpress / classes / util / array.php

array.php in WP Ultimate Post Grid 2.0, at vendor/vafpress/classes/util/array.php

136 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 class VP_Util_Array
4 {
5
6 public static function first($array)
7 {
8 if( !empty($array) and !is_null($array) )
9 {
10 return reset($array);
11 }
12 return null;
13 }
14
15 public static function deep_values($array, $the_key)
16 {
17 $result = array();
18 foreach ($array as $key => $value)
19 {
20 if (is_object($value))
21 {
22 $result[] = $value->$the_key;
23 }
24 elseif (is_array($value))
25 {
26 $result[] = $value[$the_key];
27 }
28 else
29 {
30 $result[] = $value;
31 }
32 }
33 return $result;
34 }
35
36 /**
37 * Combine array with the same $left to single array item
38 * from
39 * array( [0] => array( "name" => "a", "value" => "1" ),
40 * [1] => array( "name" => "a", "value" => "2" ),
41 * [0] => array( "name" => "b", "value" => "3" ))
42 * to
43 * array( "a" => array( "1", "2" ),
44 * "b" => 3)
45 * @param Array $array Array to unite
46 * @param Mixed $left Left side array key
47 * @param Mixed $right Right side array key
48 * @return Array United Array
49 */
50 public static function unite($array, $left, $right)
51 {
52 $result = array();
53 if(is_array($array))
54 {
55 foreach ($array as $item)
56 {
57 if(isset($result[$item[$left]]))
58 {
59 if(is_array($result[$item[$left]]))
60 $result[$item[$left]][] = $item[$right];
61 else
62 $result[$item[$left]] = array($result[$item[$left]], $item[$right]);
63 }
64 else
65 {
66 $result[$item[$left]] = $item[$right];
67 }
68 }
69 }
70 return $result;
71 }
72
73 public static function array_merge_recursive_all($paArray1, $paArray2)
74 {
75 if (!is_array($paArray1) or !is_array($paArray2)) { return $paArray2; }
76 foreach ($paArray2 AS $sKey2 => $sValue2)
77 {
78 $paArray1[$sKey2] = self::array_merge_recursive_all(@$paArray1[$sKey2], $sValue2);
79 }
80 return $paArray1;
81 }
82
83 public static function array_replace_recursive($array, $array1)
84 {
85 if (!function_exists('array_replace_recursive'))
86 {
87 if(!function_exists('recurse'))
88 {
89 function recurse($array, $array1)
90 {
91 foreach ($array1 as $key => $value)
92 {
93 // create new key in $array, if it is empty or not an array
94 if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key])))
95 {
96 $array[$key] = array();
97 }
98 // overwrite the value in the base array
99 if (is_array($value))
100 {
101 $value = recurse($array[$key], $value);
102 }
103 $array[$key] = $value;
104 }
105 return $array;
106 }
107 }
108
109 // handle the arguments, merge one by one
110 $args = func_get_args();
111 $array = $args[0];
112 if (!is_array($array))
113 {
114 return $array;
115 }
116 for ($i = 1; $i < count($args); $i++)
117 {
118 if (is_array($args[$i]))
119 {
120 $array = recurse($array, $args[$i]);
121 }
122 }
123 return $array;
124 }
125 else
126 {
127 return array_replace_recursive($array, $array1);
128 }
129 }
130
131
132 }
133
134 /**
135 * EOF
136 */