関数 wp_list_filter( )
定義ファイル :/blog/wp-includes/functions.php 14
wp_list_filter()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /** * Filters a list of objects, based on a set of key => value arguments. * * @since 3.1.0 * * @param array $list An array of objects to filter. * @param array $args Optional. An array of key => value arguments to match * against each object. Default empty array. * @param string $operator Optional. The logical operation to perform. 'AND' means * all elements from the array must match. 'OR' means only * one element needs to match. 'NOT' means no elements may * match. Default 'AND'. * @return array Array of found values. */ function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { if ( ! is_array( $list ) ) return array(); if ( empty( $args ) ) return $list; $operator = strtoupper( $operator ); $count = count( $args ); $filtered = array(); foreach ( $list as $key => $obj ) { $to_match = (array) $obj; $matched = 0; foreach ( $args as $m_key => $m_value ) { if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) $matched++; } if ( ( 'AND' == $operator && $matched == $count ) || ( 'OR' == $operator && $matched > 0 ) || ( 'NOT' == $operator && 0 == $matched ) ) { $filtered[$key] = $obj; } } return $filtered; } |