-
-
Save alinademi/549de64173e1e8b5927a49e95068fce1 to your computer and use it in GitHub Desktop.
Created a function that will return the first found match from a list of items.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Find a single item in a list based on specific criteria. | |
* | |
* @uses wp_list_filter() | |
* | |
* @param array $list | |
* @param array $args | |
* @param string $operator | |
* | |
* @return mixed|null | |
*/ | |
function wp_list_find( array $list, $args = array(), $operator = 'AND' ) { | |
$result = null; | |
$matches = wp_list_filter( $list, $args, $operator ); | |
if ( $matches ) { | |
$result = array_shift( $matches ); | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment