equal
deleted
inserted
replaced
7 */ |
7 */ |
8 |
8 |
9 /** |
9 /** |
10 * List utility. |
10 * List utility. |
11 * |
11 * |
12 * Utility class to handle operations on an array of objects. |
12 * Utility class to handle operations on an array of objects or arrays. |
13 * |
13 * |
14 * @since 4.7.0 |
14 * @since 4.7.0 |
15 */ |
15 */ |
16 class WP_List_Util { |
16 class WP_List_Util { |
17 /** |
17 /** |
32 |
32 |
33 /** |
33 /** |
34 * Temporary arguments for sorting. |
34 * Temporary arguments for sorting. |
35 * |
35 * |
36 * @since 4.7.0 |
36 * @since 4.7.0 |
37 * @var array |
37 * @var string[] |
38 */ |
38 */ |
39 private $orderby = array(); |
39 private $orderby = array(); |
40 |
40 |
41 /** |
41 /** |
42 * Constructor. |
42 * Constructor. |
100 } |
100 } |
101 |
101 |
102 $operator = strtoupper( $operator ); |
102 $operator = strtoupper( $operator ); |
103 |
103 |
104 if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) { |
104 if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) { |
105 return array(); |
105 $this->output = array(); |
|
106 return $this->output; |
106 } |
107 } |
107 |
108 |
108 $count = count( $args ); |
109 $count = count( $args ); |
109 $filtered = array(); |
110 $filtered = array(); |
110 |
111 |
137 |
138 |
138 return $this->output; |
139 return $this->output; |
139 } |
140 } |
140 |
141 |
141 /** |
142 /** |
142 * Plucks a certain field out of each object in the list. |
143 * Plucks a certain field out of each element in the input array. |
143 * |
144 * |
144 * This has the same functionality and prototype of |
145 * This has the same functionality and prototype of |
145 * array_column() (PHP 5.5) but also supports objects. |
146 * array_column() (PHP 5.5) but also supports objects. |
146 * |
147 * |
147 * @since 4.7.0 |
148 * @since 4.7.0 |
148 * |
149 * |
149 * @param int|string $field Field from the object to place instead of the entire object |
150 * @param int|string $field Field to fetch from the object or array. |
150 * @param int|string $index_key Optional. Field from the object to use as keys for the new array. |
151 * @param int|string $index_key Optional. Field from the element to use as keys for the new array. |
151 * Default null. |
152 * Default null. |
152 * @return array Array of found values. If `$index_key` is set, an array of found values with keys |
153 * @return array Array of found values. If `$index_key` is set, an array of found values with keys |
153 * corresponding to `$index_key`. If `$index_key` is null, array keys from the original |
154 * corresponding to `$index_key`. If `$index_key` is null, array keys from the original |
154 * `$list` will be preserved in the results. |
155 * `$list` will be preserved in the results. |
155 */ |
156 */ |
198 |
199 |
199 return $this->output; |
200 return $this->output; |
200 } |
201 } |
201 |
202 |
202 /** |
203 /** |
203 * Sorts the list, based on one or more orderby arguments. |
204 * Sorts the input array based on one or more orderby arguments. |
204 * |
205 * |
205 * @since 4.7.0 |
206 * @since 4.7.0 |
206 * |
207 * |
207 * @param string|array $orderby Optional. Either the field name to order by or an array |
208 * @param string|array $orderby Optional. Either the field name to order by or an array |
208 * of multiple orderby fields as $orderby => $order. |
209 * of multiple orderby fields as $orderby => $order. |
236 |
237 |
237 return $this->output; |
238 return $this->output; |
238 } |
239 } |
239 |
240 |
240 /** |
241 /** |
241 * Callback to sort the list by specific fields. |
242 * Callback to sort an array by specific fields. |
242 * |
243 * |
243 * @since 4.7.0 |
244 * @since 4.7.0 |
244 * |
245 * |
245 * @see WP_List_Util::sort() |
246 * @see WP_List_Util::sort() |
246 * |
247 * |