0

I have this following serialized string received by a Laravel Controller from an ajax call:

"address=&city=&cp=&phone_domicile=" (it can be longer)

How can I convert it to a php Object or an Array using php or a Laravel helper function? to have this following:

address => ....,
city => .....,
phone_domicile => ....

Maybe it's an easy question but I can't figure out how to do it.

Y JRB
  • 451
  • 5
  • 14

1 Answers1

0

You can use parse_str

$query = 'address=&city=&cp=&phone_domicile=';
parse_str($query,$queryStrToArray);
print_r($queryStrToArray);

Working example :- https://3v4l.org/Cg3qt

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20