<?php

namespace CCDN\Helpers;

class Arr
{

    /**
     * @param  array  $array
     * @param  string  $key
     * @param  bool  $strict
     * @return array
     */
    public static function unique($array, $key, $strict = true)
    {
        $temp_array = [];
        $key_array = [];

        foreach ($array as $index => $val) {
            if (!in_array($val[$key], $key_array, $strict)) {
                $key_array[] = $val[$key];
                $temp_array[] = $val;
            }
            unset($array[$index]);
        }
        unset($key_array);
        return $temp_array;
    }

    /**
     * @param  array  $array
     * @param  callable  $callback
     * @return array
     */
    public static function filter($array, callable $callback)
    {
        return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH);
    }
}
