src/arr/Arr.php
public static function fetch($arr, $descriptors)
    {
        $args = new ArrArguments($arr);

        foreach ($descriptors as $name => $descriptor) {
            $types = array();
            $default = null;
            $required = false;

            if (is_string($descriptor)) {
                $types = explode("|", $descriptor);
            } elseif (is_array($descriptor)) {
                $types = explode("|", Arr::get($descriptor, "type"));
                $default = Arr::get($descriptor, "default");
                $required = Arr::get(
                    $descriptor, "required", !Arr::exist($descriptor, "default")
                );
            }

            $desc = new ArrArgumentsDescriptor($types, $default, $required);
            $args->registerDescriptor($name, $desc);
        }

        return $args->fetch();
    }
public static function fetch($arr, $descriptors)
    {
        $args = new ArrArguments($arr);

        foreach ($descriptors as $name => $descriptor) {
            $types = array();
            $default = null;
            $required = false;

            if (is_string($descriptor)) {
                $types = explode("|", $descriptor);
            } elseif (is_array($descriptor)) {
                $types = explode("|", Arr::get($descriptor, "type"));
                $default = Arr::get($descriptor, "default");
                $required = Arr::get(
                    $descriptor, "required", !Arr::exist($descriptor, "default")
                );
            }

            $desc = new ArrArgumentsDescriptor($types, $default, $required);
            $args->registerDescriptor($name, $desc);
        }

        return $args->fetch();
    }
public static function fetch ( $ arr , $ descriptors ) { $ args = new ArrArguments ( $ arr ) ; foreach ( $ descriptors as $ name => $ descriptor ) { $ types = array ( ) ; $ default = null ; $ required = false ; if ( is_string ( $ descriptor ) ) { $ types = explode ( "|" , $ descriptor ) ; } elseif ( is_array ( $ descriptor ) ) { $ types = explode ( "|" , Arr :: get ( $ descriptor , "type" ) ) ; $ default = Arr :: get ( $ descriptor , "default" ) ; $ required = Arr :: get ( $ descriptor , "required" , ! Arr :: exist ( $ descriptor , "default" ) ) ; } $ desc = new ArrArgumentsDescriptor ( $ types , $ default , $ required ) ; $ args -> registerDescriptor ( $ name , $ desc ) ; } return $ args -> fetch ( ) ; }
Fetches elements from an array.

This function is especially suitable for getting optional arguments.

For example:
```php
function test($title, $message, $x, $y, $options) {
$args = Arr::fetch(func_get_args(), array(
// `title` is a required string
"title" => "string",
// `message` is an optional string and has a default value
"message" => array(
"type" => "string",
"default" => "Default message ..."
),
// `x` is an optional string or number and has a default value
"x" => array(
"type" => "string|number",
"default" => 0
),
// `y` is an optional string or number and has a default value
"y" => array(
"type" => "string|number",
"default" => 0
),
// `options` is an optional array
"options" => array(
"type"  => "array",
required => false
)
);
print_r($args);
}
// this throws an InvalidArgumentException, as 'title' is required.
test(120, 250);
```

@param array $arr         Array of mixed elements
@param array $descriptors Associative array of descriptors.

@throws InvalidArgumentException
@return array
Fetches elements from an array .