$value) { if (call_user_func($closure, $value, $key)) { $result[] = $value; } // end if; } // end foreach; return $result; } // end if; return array_filter($array); } // end filter; /** * Get a nested value inside an array. Dot notation is supported. * * @since 2.0.11 * * @param array $array The array to get the value from. * @param string $key The array key to get. Supports dot notation. * @param mixed $default The value to return ibn the case the key does not exist. * @return mixed */ public static function get($array, $key, $default = null) { if (is_null($key)) { return $array; } // end if; if (isset($array[$key])) { return $array[$key]; } // end if; foreach (explode('.', $key) as $segment) { if (!is_array($array) || !array_key_exists($segment, $array)) { return $default; } // end if; $array = $array[$segment]; } // end foreach; return $array; } // end get; /** * Set a nested value inside an array. Dot notation is supported. * * @since 2.0.11 * * @param array $array The array to modify. * @param string $key The array key to set. Supports dot notation. * @param mixed $value The value to set. * @return array */ public static function set(&$array, $key, $value) { if (is_null($key)) { return $array = $value; // phpcs:ignore } // end if; $keys = explode('.', $key); while (count($keys) > 1) { $key = array_shift($keys); if (!isset($array[$key]) || !is_array($array[$key])) { $array[$key] = array(); } // end if; $array =& $array[$key]; } // end while; $array[array_shift($keys)] = $value; return $array; } // end set; /** * Static class only. * * @since 2.0.11 */ private function __construct() {} // end __construct; } // end class Arr;