You could use array_filter to achieve this:
return is_array( $var ) ? array_filter($var, function($ele) {
return preg_match('/li(?:-[a-z_-]+)?/', $ele);
}) : '';
Pergunta
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
)
Solução
You could use array_filter to achieve this:
return is_array( $var ) ? array_filter($var, function($ele) {
return preg_match('/li(?:-[a-z_-]+)?/', $ele);
}) : '';