PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.2
Admin Columns v3.0.2
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Helper / Array.php
codepress-admin-columns / classes / Helper Last commit date
Array.php 8 years ago Date.php 8 years ago File.php 8 years ago Html.php 8 years ago Icon.php 8 years ago Image.php 8 years ago Network.php 8 years ago Post.php 8 years ago String.php 8 years ago Taxonomy.php 8 years ago User.php 8 years ago
Array.php
136 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Helper_Array {
8
9 /**
10 * Implode for multi dimensional array
11 *
12 * @since 3.0
13 *
14 * @param string $glue
15 * @param string|array $pieces
16 *
17 * @return string Imploded array
18 */
19 public function implode_recursive( $glue, $pieces ) {
20 if ( is_array( $pieces ) ) {
21 foreach ( $pieces as $r_pieces ) {
22 if ( is_array( $r_pieces ) ) {
23 $retVal[] = $this->implode_recursive( $glue, $r_pieces );
24 } else {
25 $retVal[] = $r_pieces;
26 }
27 }
28 if ( isset( $retVal ) && is_array( $retVal ) ) {
29 return implode( $glue, $retVal );
30 }
31 }
32
33 if ( is_scalar( $pieces ) ) {
34 return $pieces;
35 }
36
37 return false;
38 }
39
40 /**
41 * Replace a single key in an associative array
42 *
43 * @since 2.2.7
44 *
45 * @param array $input Input array.
46 * @param int|string $old_key Key to replace.
47 * @param int|string $new_key Key to replace $old_key with
48 */
49 public function key_replace( $input, $old_key, $new_key ) {
50 $keys = array_keys( $input );
51 $old_key_pos = array_search( $old_key, $keys );
52
53 if ( $old_key_pos === false ) {
54 return $input;
55 }
56
57 $keys[ $old_key_pos ] = $new_key;
58
59 return array_combine( $keys, array_values( $input ) );
60 }
61
62 /**
63 * Indents any object as long as it has a unique id and that of its parent.
64 *
65 * @since 1.0
66 *
67 * @param array $array
68 * @param int $parentId
69 * @param string $parentKey
70 * @param string $selfKey
71 * @param string $childrenKey
72 *
73 * @return array Indented Array
74 */
75 public function indent( $array, $parentId = 0, $parentKey = 'post_parent', $selfKey = 'ID', $childrenKey = 'children' ) {
76 $indent = array();
77
78 $i = 0;
79 foreach ( $array as $v ) {
80 if ( $v->$parentKey == $parentId ) {
81 $indent[ $i ] = $v;
82 $indent[ $i ]->$childrenKey = $this->indent( $array, $v->$selfKey, $parentKey, $selfKey );
83
84 $i++;
85 }
86 }
87
88 return $indent;
89 }
90
91 /**
92 * Remove empty values from array
93 *
94 * @param array $array
95 *
96 * @return array
97 */
98 public function filter( $array ) {
99 return array_filter( $array, array( ac_helper()->string, 'is_not_empty' ) );
100 }
101
102 /**
103 * Insert element into array at specific position
104 *
105 * @param array $array
106 * @param array $insert
107 * @param string $position
108 *
109 * @return array
110 */
111 public function insert( $array, $insert, $position ) {
112 $new = array();
113 foreach ( $array as $key => $value ) {
114 $new[ $key ] = $value;
115 if ( $key === $position ) {
116 $new = array_merge( $new, $insert );
117 }
118
119 }
120
121 return $new;
122 }
123
124 /**
125 * Get duplicates from array
126 *
127 * @param array $array
128 *
129 * @return array
130 */
131 public function get_duplicates( array $array ) {
132 return array_intersect( $array, array_unique( array_diff_key( $array, array_unique( $array ) ) ) );
133 }
134
135 }
136