return the prev element of a specific key

@param $arr
@param $nested_key
@param int $iteration
@return bool|mixed
779222
public static function array_prev_element($arr, $nested_key, $iteration = 1)
    {
        foreach ($arr as $key => $v) {
            if ($key == $nested_key) {
                for ($i = 0; $i < $iteration; $i++) {
                    $return = prev($arr);
                }

                if (!empty($return)) {
                    return $return;
                } else {
                    return false;
                }
            }

            next($arr);
        }

        return false;
    }
474960
function (digest, iterationCount) {

        var derive = function (password, salt, len) {
            var key, i, tmpBuf;
            if (len > digest.digestLength()) {
                throw "Key length larger than digest length";
            }
            digest.reset();
            digest.update(password);
            digest.update(salt);
            tmpBuf = digest.finalize();
            for (i = 1; i < iterationCount; i++) {
                tmpBuf = digest.digest(tmpBuf);
            }
            return tmpBuf.slice(0, len);
        };

        return {
            deriveKey: function (password, salt, len) {
                return derive(convertToUint8Array(password), convertToUint8Array(salt), len);
            }
        };
    }
800312
public static function filter_keys($arr, $keys)
    {
        foreach ($arr as $key => $v) {
            if (!in_array($key, $keys)) {
                unset($arr[$key]);
            }
        }

        return $arr;
    }
987108
def get_nested(self, *args):
        
        data = self.data
        for key in args:
            if key not in data:
                return None
            data = data[key]
        return data
93720
public static function exists($arr, $key) {
        // If it's an object, index directly because array_key_exists doesn't
        // work with the ArrayAccess interface. Otherwise, check if it implements
        // ArrayAccess and fall back to array_key_exists.
        if(is_object($arr)) {
            return $arr->offsetExists($key);
        }
        if(is_array($arr)) {
            return array_key_exists($key, $arr);
        }

        return false;
    }
871246
public static function getPrevKey($key, array $array) {
		$keys = array_keys($array);
		$found_index = array_search($key, $keys);
		if($found_index === false || $found_index === 0)
			return false;
		return $keys[$found_index - 1];
	}
203572
public static function containsNotAnyKey(array $arr, array $keys)
    {
        foreach ($keys as $key) {
            if (isset($arr[$key]))
                return false;
        }

        return true;
    }
1273395
public static function get($arr, $key, $default=null) {
        return self::exists($arr, $key) ? $arr[$key]:$default;
    }
1032637
public static function isIterator($arr) {
        if (!is_array($arr)) {
            return false;
        }

        foreach (array_keys($arr) as $key) {
            if (!is_numeric($key)) {
                return false;
            }
        }

        return true;
    }
839569
public function orderElements($arr) {
        $result = true;

        // Create a new array
        $newarr = array();
        if (!empty($arr)) {
            $currentelement = null;
            // Get the element without previous
            foreach($arr as $key => $element) {
                if (!$element->getPrevious()) {
                    $currentelement = $arr[$key];
                    $newarr[0] = $arr[$key];
                }
            }
            if (!$currentelement) {
                $result = false;
            }
            // Follow the next rules
            $counter = 1;
            while ($result && $currentelement->getNext()) {
                $i = $this->findObjectInArray($currentelement->getNext(), $arr);
                $currentelement = $arr[$i];
                $newarr[$counter] = $arr[$i];
                $counter++;
            }
            // Compare number of elements between original and new array
            if ($result && count($arr) != count($newarr)) {
                $result = false;
            } else if ($newarr) {
                $result = $newarr;
            } else {
                $result = false;
            }
        } else {
            $result = array();
        }
        return $result;
    }
675373
private function ___toObjectIterator($array, $depth = 'ALL', $counter = 0)
    {
        $object = new SplArrayObject();

        if ($this->count() > 0) {
            foreach ($array as $key => $value) {
                if (strlen($key)) {
                    if (is_array($value)) {
                        if ($depth == 'ALL') {
                            $object->offsetSet($key, $this->___toObjectIterator($value, $depth));
                        } elseif (is_numeric($depth)) {
                            if ($counter != $depth) {
                                $object->offsetSet($key, $this->___toObjectIterator($value, $depth, $counter));
                            } else {
                                $object->offsetSet($key, $value);
                            }
                        } elseif (is_string($depth) && $key == $depth) {
                            $object->offsetSet($key, $value);
                        } elseif (is_array($depth) && in_array($key, $depth)) {
                            $object->offsetSet($key, $value);
                        } else {
                            $object->offsetSet($key, $this->___toObjectIterator($value, $depth));
                        }
                    } else {
                        $object->offsetSet($key, $value);
                    }
                }
            }
        }

        return $object;
    }
621335
static function getArray($arr,$key,$default=array())
    {
        $value = Utility::get($arr, $key);
        return ($value!=null)?explode(',', $value):$default;
    }
795807
public static function reIndex($arr)
	{
		// reindex this level
		$arr = array_merge($arr);

		foreach ($arr as &$v)
		{
			is_array($v) and $v = static::reIndex($v);
		}

		return $arr;
	}
1323971
protected function fetchByKeyPart(array $arr_key_parts, $str_setter)
    {

        // Build the query
        $obj_request = (object)[
            'keys' => []
        ];
        $this->applyTransaction($obj_request);

        // Add keys
        foreach($arr_key_parts as $str_key_part) {
            $obj_element = (object)['kind' => $this->obj_schema->getKind()];
            if('setId' === $str_setter) {
                $obj_element->id = $str_key_part;
            } elseif ('setName' === $str_setter) {
                $obj_element->name = $str_key_part;
            }
            $obj_key = (object)['path' => [$obj_element]];
            $this->applyPartition($obj_key);
            $obj_request->keys[] = $obj_key;
        }

        // Run
        $this->executePostRequest('lookup', $obj_request);

        // Extract results
        $arr_mapped_results = [];
        if(isset($this->obj_last_response->found) && is_array($this->obj_last_response->found)) {
            $arr_mapped_results = $this->createMapper()->mapFromResults($this->obj_last_response->found);
        }
        $this->obj_schema = null; // Consume Schema
        return $arr_mapped_results;
    }
1371340
function map(arr, iterator) {
    var result = [], i;
    if (Array.prototype.map) {
      return Array.prototype.map.call(arr, iterator);
    }
    for (i = 0; i < arr.length; i++) {
      result.push(iterator(arr[i]));
    }
    return result;
  }
1209777
public static function _arrayToObjects ($arr, $key = FALSE)
	{
		
		// Set object array
		
		$objs	=  new Resource\Model\Collection;
		
		// If no data

		if (!$arr)
		{
			return $objs;
		}
		
		// For each row
		
		foreach ($arr as $row)
		{

			// Create the object

			$obj	= new static;

			// Set each attribute value

			foreach ($row as $name => $val)
			{

				if ($obj->attributeExists ($name))
				{
					$obj->iset ($name, $val, FALSE, TRUE);
				}

			}
			
			// Add to the array
			
			if ($key && isset ($row[$key]))
			{
				$objs[$row[$key]]	= $obj;
			}
			else
			{
				$objs[]	= $obj;
			}

		}
		
		// Return the objects
		
		return $objs;
		
	}
864852
function forEach(arr, iter) {
    return reduce(arr, function(val, el, key) {
        return iter(el, key);
    });
}