<?php
/**
 *
 * User: Artur Pilch <artur.pi@modulesgarden.com>
 * Date: 2018-08-02
 * Time: 11:12
 */

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\Basics;


class Arrays
{
    public static function getMin($values)
    {
        return min($values);
    }

    public static function getMax($array)
    {
        return max($array);
    }
    public static function getMinInArray($array)
    {
        $out = [];
        foreach ($array as $key => $values)
        {
            $out[$key] = Arrays::getMin($values);
        }
        return $out;
    }

    public static function replaceKeys($data, $whereKeyIsOldKeyAndValueIsNewKey)
    {
        foreach ($whereKeyIsOldKeyAndValueIsNewKey as $key => $value)
        {
            if (!isset($data[$key]))
            {
                continue;
            }
            $data[$value] = $data[$key];
            unset($data[$key]);
        }
        return $data;
    }

    public static function addPrefixToValue($array, $prefix)
    {
        foreach ($array as &$value)
        {
            if(stripos($value, $prefix, 0) !== false)
            {
                continue;
            }
            $value = $prefix. $value;
        }
        return $array;
    }


}