src/Traits/Collections.php
public static function where(array $array = [], array $key = [], bool $keepKeys = false): array
    {
        $result = [];

        foreach ($array as $k => $v) {
            $not = false;

            foreach ($key as $j => $w) {
                if (__::isArray($w)) {
                    $inKV = $v[$j] ?? [];
                    if (count(array_intersect_assoc($w, $inKV)) == 0) {
                        $not = true;
                        break;
                    }
                } else {
                    if (!isset($v[$j]) || $v[$j] != $w) {
                        $not = true;
                        break;
                    }
                }
            }

            if ($not == false) {
                if ($keepKeys) {
                    $result[$k] = $v;
                } else {
                    $result[] = $v;
                }
            }
        }

        return $result;
    }
public static function where(array $array = [], array $key = [], bool $keepKeys = false): array
    {
        $result = [];

        foreach ($array as $k => $v) {
            $not = false;

            foreach ($key as $j => $w) {
                if (__::isArray($w)) {
                    $inKV = $v[$j] ?? [];
                    if (count(array_intersect_assoc($w, $inKV)) == 0) {
                        $not = true;
                        break;
                    }
                } else {
                    if (!isset($v[$j]) || $v[$j] != $w) {
                        $not = true;
                        break;
                    }
                }
            }

            if ($not == false) {
                if ($keepKeys) {
                    $result[$k] = $v;
                } else {
                    $result[] = $v;
                }
            }
        }

        return $result;
    }
public static function where ( array $ array = [ ] , array $ key = [ ] , bool $ keepKeys = false ) : array { $ result = [ ] ; foreach ( $ array as $ k => $ v ) { $ not = false ; foreach ( $ key as $ j => $ w ) { if ( __ :: isArray ( $ w ) ) { $ inKV = $ v [ $ j ] ?? [ ] ; if ( count ( array_intersect_assoc ( $ w , $ inKV ) ) == 0 ) { $ not = true ; break ; } } else { if ( ! isset ( $ v [ $ j ] ) || $ v [ $ j ] != $ w ) { $ not = true ; break ; } } } if ( $ not == false ) { if ( $ keepKeys ) { $ result [ $ k ] = $ v ; } else { $ result [ ] = $ v ; } } } return $ result ; }
Return data matching specific key value condition

@usage __::where($a, ['age' => 16]);
>> [['name' => 'maciej', 'age' => 16]]

@param array $array    array of values
@param array $key      condition in format of ['KEY'=>'VALUE']
@param bool  $keepKeys keep original keys

@return array
Return data matching specific key value condition