Split and swap the array key?

Asked

Viewed 223 times

0

When using the function split in a string obviously the keys will be enumerated from 0 to ... but I would like to choose which key should be, using just one of the words that will be in the string, example to help simplify:

$string = "key1=xxx&key2=xxx&key3=xxx&key4=xxx ...";

When using split separating the string in & i would like the keys to be sorted according to the "key" and stay like this:

Array
(
    [key1] => xxx1
    [key2] => xxx2
    [key3] => xxx3
    [key4] => xxx4
)

How can I do that?

  • 1

    I think that that can help.

  • 1

    Thanks @rray only parse_str was enough to solve the problem :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.