문제

I'm using a method that takes an array of words and removes any that don't match the following:

return is_array( $var ) ? array_intersect( $var,
    array(
        'current_page_item',
        'current-menu-item',
        'current_page_parent',
        'current_page_ancestor',
        'current-menu-ancestor',
        'first',
        'last',
        'vertical',
        'horizontal'
    )
) : '';

How can I modify this so that I can include li(?:-[a-z_-]+)?? (Examples: li, li-align_left, li-magnify)

도움이 되었습니까?

해결책

You could use array_filter to achieve this:

return is_array( $var ) ? array_filter($var, function($ele) {
  return preg_match('/li(?:-[a-z_-]+)?/', $ele);
}) : '';
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top