Reputation: 13
after using urldecode
:
I get a query string like this:
type[0]=1&type[1]=2
the problem is that I can't remove the keys, so what I want is this:
type[]=1&type[]=2
a query string without indexes?
Upvotes: 1
Views: 256
Reputation: 1571
You can use pre_replace
to remove indexes.
Snippet
$qryStr = 'type[0]=1&type[1]=2';
$result = preg_replace('/\[(\d+)\]/', '[]', $qryStr);
echo $result;
Output
type[]=1&type[]=2
Live demo
Bonus: If indexs are associative keys then replace \d+
with \w+
Upvotes: 2