Beispiel #1
0
 protected function in_multi_array($needle, $haystack, $strict = FALSE)
 {
     if (defined('STRICT_TYPES') && CAMEL_CASE == '1') {
         return (bool) self::parameters(['needle' => DT::MIXED, 'haystack' => DT::TYPE_ARRAY, 'strict' => DT::BOOL])->call(__FUNCTION__)->with($needle, $haystack, $strict)->returning(DT::BOOL);
     } else {
         return (bool) in_multi_array($needle, $haystack, $strict);
     }
 }
Beispiel #2
0
function in_multi_array($needle, array $haystack, $strict = FALSE)
{
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || is_array($item) && in_multi_array($needle, $item, $strict)) {
            return TRUE;
        }
    }
    return FALSE;
}
Beispiel #3
0
/** like in_array only for multible arrays
 * Returns true if needle is found in haystack
 *
 * @param   $needle string or integer
 * @param   $haystack array or multiarray
 *
 * @return  returns boolean
 */
function in_multi_array($needle, $haystack)
{
    $in_multi_array = false;
    if (in_array($needle, $haystack)) {
        $in_multi_array = true;
    } else {
        $keys = array_keys($haystack);
        reset($keys);
        $key = current($keys);
        if (empty($key)) {
            $key = 'NULL_WAS_THE_KEY';
            // 0 and nothing are the same for php
        }
        while ($key) {
            if ($key == 'NULL_WAS_THE_KEY') {
                $key = 0;
            }
            if (count($haystack) > $key and is_array($haystack[$key])) {
                if (in_multi_array($needle, $haystack[$key])) {
                    $in_multi_array = true;
                    break;
                }
            }
            $key = next($keys);
        }
    }
    return $in_multi_array;
}
Beispiel #4
0
function in_multi_array($needle, $haystack)
{
    $in_multi_array = false;
    if (in_array($needle, $haystack)) {
        $in_multi_array = true;
    } else {
        for ($i = 0; $i < sizeof($haystack); $i++) {
            if (is_array($haystack[$i])) {
                if (in_multi_array($needle, $haystack[$i])) {
                    $in_multi_array = true;
                    break;
                }
            }
        }
    }
    return $in_multi_array;
}
function in_multi_array($needle, $haystack)
{
    if (@$haystack[$needle]) {
        return $haystack[$needle];
    } else {
        foreach ($haystack as $key => $val) {
            if (is_array($val)) {
                if ($result = in_multi_array($needle, $val)) {
                    return $result;
                }
            }
        }
    }
    return false;
}
Beispiel #6
0
function in_multi_array($needle, $haystack)
{
    $in_multi_array = false;
    if (in_array($needle, $haystack)) {
        $in_multi_array = true;
    } else {
        foreach ($haystack as $key => $value) {
            if (is_array($value)) {
                if (in_multi_array($needle, $value)) {
                    $in_multi_array = true;
                    break;
                }
            }
        }
    }
    return $in_multi_array;
}