Sorts an array by value and returns a new instance

@param array $arr
@return array
494428
public static function getSortedArrayByValue($arr)
    {
        $duplicate = self::copyArray($arr);

        if ($duplicate === null) {
            return null;
        }

        asort($duplicate);

        return $duplicate;
    }
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;
    }
601946
public static function values($arr)
    {
        if (!is_array($arr)) {
            return '';
        }
        $arr = array_values($arr);
        foreach ($arr as &$v) {
            $v = static::value($v);
        }
        return implode(',', $arr);
    }
242191
function diffKeys($arr) {
        if($arr instanceof self) {
            $arr = $arr->all();
        }
        
        return (new self(\array_diff_key($this->data, $arr)));
    }
389028
public static function createFromArray(array $array)
    {
        $sortBy = self::create();
        $sortBy->sortsBy = array_map(function (array $element) {
            if (
                self::RANDOM !== $element &&
                self::SCORE !== $element
            ) {
                $element['type'] = $element['type'] ?? SortBy::TYPE_FIELD;
            }

            if (isset($element['filter'])) {
                $element['filter'] = Filter::createFromArray($element['filter']);
            }

            if (
                isset($element['coordinate']) &&
                is_array($element['coordinate'])
            ) {
                $element['coordinate'] = Coordinate::createFromArray($element['coordinate']);
            }

            return $element;
        }, $array);

        return $sortBy;
    }
1369590
public static function array_pop_rand(array &$arr) {
		$length = \count($arr);

		if (! $length) {
			return false;
		}

		// Nothing random about an array with one thing.
		if (1 === $length) {
			return static::array_pop_top($arr);
		}

		$keys = \array_keys($arr);
		$index = static::random_int(0, $length - 1);

		return $arr[$keys[$index]];
	}
1025950
function clone(arr) {
              	var newArr = [];
              	for (var i=0; i<arr.length; i++) {
              		newArr.push(arr[i]);
              	}
              	return newArr;
              }
100704
public static function array_to_object($arr)
    {
        if (gettype($arr) != 'array') {
            return $arr;
        }
        foreach ($arr as $k => $v) {
            if (gettype($v) == 'array' || getType($v) == 'object') {
                $arr[$k] = self::array_to_object($v);
            }
        }
        return (object)$arr;
    }
165
@SuppressWarnings("unchecked")
	public <T> void sort(Arr arr, Comparator<T> c) {
		int l = arr.getLength();
		Object[] objs = new Object[l];
		for (int i=0; i<l; i++) {
			objs[i] = arr.get(i);
		}
		Arrays.sort((T[])objs, c);
		for (int i=0; i<l; i++) {
			arr.put(i, objs[i]);
		}
	}
817308
public static function unique($arr)
	{
		// filter out all duplicate values
		return array_filter(
			$arr,
			function ($item)
			{
				// contrary to popular belief, this is not as static as you think...
				static $vars = array();

				if (in_array($item, $vars, true))
				{
					// duplicate
					return false;
				}
				else
				{
					// record we've had this value
					$vars[] = $item;

					// unique
					return true;
				}
			}
		);
	}
1160041
public static function from_array($arr)
    {
        $obj = new rcube_message_header;
        foreach ($arr as $k => $v)
            $obj->set($k, $v);

        return $obj;
    }
1067048
public function fromArray($arr)
    {
        $class = $this->getModel();
        foreach ($arr as $element) {
            /** @var $obj BaseObject */
            $obj = new $class();
            $obj->fromArray($element);
            $this->append($obj);
        }
    }
1251778
public static function before($arr, $i) {
		$res = [];
		foreach($arr as $k=>$v) {
			if($k === $i)
				return $res;
			$res[$k] = $v;
		}
		return $res;
	}
1324456
function intersect($arr) {
        if($arr instanceof self) {
            $arr = $arr->all();
        }
        
        return (new self(\array_intersect($this->data, $arr)));
    }
985156
public function fromArray($arr)
    {
        $class = $this->getFullyQualifiedModel();
        foreach ($arr as $element) {
            /** @var $obj ActiveRecordInterface */
            $obj = new $class();
            $obj->fromArray($element);
            $this->append($obj);
        }
    }
321252
public function setOptionArray(array $arr) {
        foreach($arr as $option => $value) {
            CurlOptions::checkOptionValue($option, $value);
        }

        return curl_setopt_array($this->handle, $arr);
    }
241806
public static function arrayKeyLower($arr)
    {
        return array_map(function($item){
            if(is_array($item)) {
                $item = self::arrayKeyLower($item);
            }
            return $item;
        },array_change_key_case($arr,CASE_LOWER));
    }