function array_key_exists_r($needle, $haystack)
{
    $result = array_key_exists($needle, $haystack);
    if ($result) {
        return $result;
    }
    foreach ($haystack as $v) {
        if (is_array($v)) {
            $result = array_key_exists_r($needle, $v);
        }
        if ($result) {
            return $result;
        }
    }
    return $result;
}
function array_key_exists_r($needle, $haystack)
{
    $result[0] = array_key_exists($needle, $haystack);
    if ($result[0]) {
        $result[1] = $haystack[$needle];
        return $result;
    }
    foreach ($haystack as $v) {
        if (is_array($v) || is_object($v)) {
            $result = array_key_exists_r($needle, $v);
        }
        if ($result[0]) {
            return $result;
        }
    }
    return $result;
}
Beispiel #3
0
function rsort_by_key(array &$array, $key, $sort_flags = SORT_NUMERIC)
{
    // use $sort_flags in the future
    return usort($array, function ($arr_a, $arr_b) use($key) {
        // Get Values (nearest)
        array_key_exists_r($key, $arr_a, $val_a);
        array_key_exists_r($key, $arr_b, $val_b);
        return $val_b - $val_a;
    });
    return false;
}
Beispiel #4
0
function array_key_exists_r($needle, $haystack)
{
    if (array_key_exists($needle, $haystack)) {
        return TRUE;
    }
    foreach ($haystack as $v) {
        if (is_array($v) || is_object($v)) {
            if (array_key_exists_r($needle, $v)) {
                return TRUE;
            }
        }
    }
    return FALSE;
}
Beispiel #5
0
 function iterate($k, $hash = NULL)
 {
     $h =& $this->resolve_hash($hash);
     #echo "\$hash:";
     #var_dump($hash);
     $vals = $this->_calculate_valid_values();
     $ret = $vals[$k];
     /*if (!$ret) {
     			echo "\$vals ($k, $this, ".$this->word()->id()."):";
     			var_dump($vals);
     			var_dump($this->word()->id());
     			die($this->word()->id()." was not valid");
     		}/**/
     if (FLAT_STORAGE) {
         if ($h !== NULL) {
             foreach ($vals[$k] as $i => $k) {
                 $found = FALSE;
                 foreach (array_keys($h) as $_) {
                     if (!PATH($this->_mgr, $_)->issub($this)) {
                         continue;
                     }
                     foreach (explode("/", $_) as $__) {
                         if ($__ === $k) {
                             $found = TRUE;
                             break;
                         }
                     }
                     if ($found) {
                         break;
                     }
                 }
                 if (!$found) {
                     //error_log("$k does not exist under ".$this);
                     unset($ret[$i]);
                 }
                 //else error_log("$k exists under ".$this);
             }
         }
         return array_values($ret);
     }
     if ($h !== NULL) {
         foreach (array_values($ret) as $i => $k) {
             if (!array_key_exists_r($k, $h)) {
                 unset($ret[$i]);
             }
         }
     }
     #echo "\$ret:";
     #var_dump($ret);
     return array_values($ret);
 }