глаз тв
глаз тв

Reputation: 13

php urldecode without keys in a multidimensional array

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

Answers (1)

Shahnawaz Kadari
Shahnawaz Kadari

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+

preg_replace

Upvotes: 2

Related Questions