Reconstruct previous/next attributes.
@param array $arr
@return bool true if $arr modified
194718
public function fixPrevNext(&$arr) {
        $tweaked = false;

        $prev = null;
        foreach ($arr as $key=>$el) {
            $prev_value = $arr[$key]->previous;
            $next_value = $arr[$key]->next;

            $arr[$key]->next     = null;
            $arr[$key]->previous = null;
            if ($prev !== null) {
                $arr[$prev]->next    = $arr[$key]->name;
                $arr[$key]->previous = $arr[$prev]->name;
            }
            $prev = $key;

            if ($prev_value != $arr[$key]->previous or $next_value != $arr[$key]->next) {
                $tweaked = true;
            }
        }

        return $tweaked;
    }
1067048
public function fromArray($arr)
    {
        $class = $this->getModel();
        foreach ($arr as $element) {
            /** @var $obj BaseObject */
            $obj = new $class();
            $obj->fromArray($element);
            $this->append($obj);
        }
    }
536773
protected static function get_instances($arr) {
        $result = array();
        foreach ($arr as $key => $sub) {
            $result[$key] = new rule($sub);
        }
        return $result;
    }
856068
protected function exist(Array $arr)
    {
        $return = [];

        foreach ($arr as $name) {
            $return[$name] = $this->have($name);
        }

        if (count($return) === 1) {
            return array_values($return)[0];
        }

        if (count($return) > 1) {
            return $return;
        }

        return null;
    }
680620
protected static function keyExistsMultiple(array $arr, array $keys)
    {
        $return = [];
        foreach ($keys as $key) {
            $return[$key] = static::keyExists($arr, $key);
        }

        return $return;
    }
750944
public static function isAssoc(array $arr)
    {
        return (is_array($arr) && (!count($arr) || count(array_filter(array_keys($arr),'is_string')) == count($arr)));
    }
746639
public function fromArray($arr)
    {
        if (!empty($arr)) {
            // Iterate over each element in array
            foreach ($arr as $k => $v) {
                // If the value is an array, it means, it is an object after conversion
                if (is_array($v)) {
                    // Determine the class of the object
                    if (($clazz = ReflectionHelper::getPropertyClass(get_class($this), $k)) != null) {
                        // If the value is an associative array, it means, its an object. Just make recursive call to it.
                        if (empty($v)) {
                            if (ReflectionHelper::isPropertyClassArray(get_class($this), $k)) {
                                // It means, it is an array of objects.
                                $this->assignValue($k, array());
                                continue;
                            }
                            $o = new $clazz();
                            //$arr = array();
                            $this->assignValue($k, $o);
                        } elseif (ArrayHelper::isAssocArray($v)) {
                            /** @var self $o */
                            $o = new $clazz();
                            $o->fromArray($v);
                            $this->assignValue($k, $o);
                        } else {
                            // Else, value is an array of object/data
                            $arr = array();
                            // Iterate through each element in that array.
                            foreach ($v as $nk => $nv) {
                                if (is_array($nv)) {
                                    $o = new $clazz();
                                    $o->fromArray($nv);
                                    $arr[$nk] = $o;
                                } else {
                                    $arr[$nk] = $nv;
                                }
                            }
                            $this->assignValue($k, $arr);
                        }
                    } else {
                        $this->assignValue($k, $v);
                    }
                } else {
                    $this->assignValue($k, $v);
                }
            }
        }
        return $this;
    }
173291
public static function fromUnicode($arr)
    {
        ob_start();

        foreach (array_keys($arr) as $k) {
            # ASCII range (including control chars)
            if (($arr[$k] >= 0) && ($arr[$k] <= 0x007f)) {
                echo chr($arr[$k]);
                # 2 byte sequence
            } else {
                if ($arr[$k] <= 0x07ff) {
                    echo chr(0xc0 | ($arr[$k] >> 6));
                    echo chr(0x80 | ($arr[$k] & 0x003f));
                    # Byte order mark (skip)
                } else {
                    if ($arr[$k] == 0xFEFF) {
                        // nop -- zap the BOM

                        # Test for illegal surrogates
                    } else {
                        if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) {
                            // found a surrogate
                            trigger_error(
                                'utf8_from_unicode: Illegal surrogate ' .
                                'at index: ' . $k . ', value: ' . $arr[$k],
                                E_USER_WARNING
                            );

                            return false;
                            # 3 byte sequence
                        } else {
                            if ($arr[$k] <= 0xffff) {
                                echo chr(0xe0 | ($arr[$k] >> 12));
                                echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
                                echo chr(0x80 | ($arr[$k] & 0x003f));
                                # 4 byte sequence
                            } else {
                                if ($arr[$k] <= 0x10ffff) {
                                    echo chr(0xf0 | ($arr[$k] >> 18));
                                    echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
                                    echo chr(0x80 | (($arr[$k] >> 6) & 0x3f));
                                    echo chr(0x80 | ($arr[$k] & 0x3f));
                                } else {
                                    trigger_error(
                                        'utf8_from_unicode: Codepoint out of Unicode range ' .
                                        'at index: ' . $k . ', value: ' . $arr[$k],
                                        E_USER_WARNING
                                    );

                                    // out of range
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }

        $result = ob_get_contents();
        ob_end_clean();

        return $result;
    }
121514
public static function remove_empty($arr)
    {
        if (empty($arr)) {
            return null;
        }
        foreach ($arr as $key => $value) {
            if (is_array($value)) {
                $arr[$key] = self::remove_empty($value);
            } else {
                if (empty($value)) {
                    unset($arr[$key]);
                } else {
                    $arr[$key] = $value;
                }
            }
        }
        return $arr;
    }
1070524
private function recordOffset($arr)
    {
        list($this->int_offset, $this->str_start_cursor) = $this->getIntStringFromValue($this->lookupToken($arr['offset']));
        return '';
    }
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;
    }
745616
public static function flatten(array $arr): array
    {
        $i = 0;
        $len = count($arr);
        for (; $i<$len; $i++) {
            if (is_array($arr[$i])) {
                array_splice($arr, $i, 1, $arr[$i]);
                $len--;
            }
        }
        return $arr;
    }
138823
public function isArrayValueSet($pos, $arr)
    {
        if (is_array($arr) && array_key_exists($pos, $arr) && !empty($arr[$pos])) {
            return true;
        }
    }
281931
protected function isMultiArray($arr)
    {
        if (!is_array($arr)) {
            return false;
        }

        rsort($arr);

        return isset($arr[0]) && is_array($arr[0]);
    }
1190907
function _updateAttrArray(&$attr1, $attr2)
    {
        if (!is_array($attr2)) {
            return false;
        }
        foreach ($attr2 as $key => $value) {
            $attr1[$key] = $value;
        }
    }
1192060
public static function array_next_element($arr, $nested_key, $iteration = 1)
    {
        foreach ($arr as $key => $v) {
            current($arr);

            if ($key == $nested_key) {
                for ($i = 0; $i < $iteration; $i++) {
                    $return = next($arr);
                }

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

            next($arr);
        }

        return false;
    }
6161
public static function createFromArray(array $arr)
    {
        $ret = new Url;
        $keys = ['scheme','user','pass','host','port','path','query','fragment'];
        foreach ($keys as $key) {
            if (array_key_exists($key, $arr)) {
                $fn = 'set'.ucfirst($key);
                call_user_func([$ret, $fn], $arr[$key]);
            }
        }
        return $ret;
    }