ap_search_array( array $arr, string $key, mixed $value )

Description #

Search array by key and value.

Parameters #

  • $arr
    array (Required) Array to search.
  • $key
    string (Required) Array key to search.
  • $value
    mixed (Required) Value of key supplied.

Source #

File: includes/functions.php

function ap_search_array( $arr, $key, $value ) {
	$results = array();

	if ( is_array( $arr ) ) {
		if ( isset( $arr[ $key ] ) && $arr[ $key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
			$results[] = $arr;
		}

		foreach ( $arr as $subarray ) {
			$results = array_merge( $results, ap_search_array( $subarray, $key, $value ) );
		}
	}

	return $results;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment