/** * Filter the array using the given Closure. * * @param array $array * @param \Closure $callback * @return array */ function wpdevsclub_array_where($array, Closure $callback) { return Arr::where($array, $callback); }
function test_where() { $array = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8); $this->assertEquals(array('b' => 2, 'd' => 4, 'f' => 6, 'h' => 8), Arr::where($array, function ($key, $value) { return $value % 2 === 0; })); $this->assertEquals(array('c' => 3, 'f' => 6), wpdevsclub_array_where($array, function ($key, $value) { return $value % 3 === 0; })); }
/** * Checks if the parameter key is a valid array, which means: * 1. Does it the key exists (which can be dot notation) * 2. If the value is an array * 3. Is the value empty, i.e. when $valid_if_not_empty is set * * @since 1.0.0 * * @param string $parameter_key * @param bool $valid_if_not_empty * @return bool */ public function is_array($parameter_key, $valid_if_not_empty = true) { return Arr_Helpers::is_array($this->config, $parameter_key, $valid_if_not_empty); }