Documentation for crwlr / url (v0.1)

Getting/Setting the Query-String Component as/from Array

If you're after the query of a url you may want to get it as an array. Don't worry, nothing easier than that:

$url = Url::parse('https://www.example.com/foo?bar=baz&key=value');
var_dump($url->queryArray());

Output

array(2) {
  ["bar"]=>
  string(3) "baz"
  ["key"]=>
  string(5) "value"
}

And the same method can be used to set the whole query string from an array:

$url = Url::parse('https://www.example.com/foo');
$url->queryArray(['param' => 'value', 'yo' => 'lo', 'crwlr' => 'url']);
var_dump($url->__toString());

Output

string(55) "https://www.example.com/foo?param=value&yo=lo&crwlr=url"