equal
deleted
inserted
replaced
46 * @since 4.7.0 |
46 * @since 4.7.0 |
47 * |
47 * |
48 * @param array $input Array to perform operations on. |
48 * @param array $input Array to perform operations on. |
49 */ |
49 */ |
50 public function __construct( $input ) { |
50 public function __construct( $input ) { |
51 $this->output = $this->input = $input; |
51 $this->output = $input; |
|
52 $this->input = $input; |
52 } |
53 } |
53 |
54 |
54 /** |
55 /** |
55 * Returns the original input array. |
56 * Returns the original input array. |
56 * |
57 * |
99 |
100 |
100 $count = count( $args ); |
101 $count = count( $args ); |
101 $filtered = array(); |
102 $filtered = array(); |
102 |
103 |
103 foreach ( $this->output as $key => $obj ) { |
104 foreach ( $this->output as $key => $obj ) { |
104 $to_match = (array) $obj; |
|
105 |
|
106 $matched = 0; |
105 $matched = 0; |
|
106 |
107 foreach ( $args as $m_key => $m_value ) { |
107 foreach ( $args as $m_key => $m_value ) { |
108 if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) { |
108 if ( is_array( $obj ) ) { |
109 $matched++; |
109 // Treat object as an array. |
110 } |
110 if ( array_key_exists( $m_key, $obj ) && ( $m_value == $obj[ $m_key ] ) ) { |
111 } |
111 $matched++; |
112 |
112 } |
113 if ( |
113 } elseif ( is_object( $obj ) ) { |
114 ( 'AND' == $operator && $matched == $count ) || |
114 // Treat object as an object. |
115 ( 'OR' == $operator && $matched > 0 ) || |
115 if ( isset( $obj->{$m_key} ) && ( $m_value == $obj->{$m_key} ) ) { |
116 ( 'NOT' == $operator && 0 == $matched ) |
116 $matched++; |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 if ( ( 'AND' === $operator && $matched === $count ) |
|
122 || ( 'OR' === $operator && $matched > 0 ) |
|
123 || ( 'NOT' === $operator && 0 === $matched ) |
117 ) { |
124 ) { |
118 $filtered[ $key ] = $obj; |
125 $filtered[ $key ] = $obj; |
119 } |
126 } |
120 } |
127 } |
121 |
128 |