Is there any good way to parse a string like a = 1 & B = 2 in PHP to solve a problem? an interface will return a = 1 & B = 2 & amp; c = 3 ...... the number of parameters in this format is not fixed, sometimes 10 or 20, and the order is not fixed, sometimes it is a = 1. could you tell me how to parse strings like a = 1 & B = 2 in PHP?
Encountered a problem
An interface returns a = 1 & B = 2 & c = 3 ...... the number of parameters in this format is not fixed, sometimes 10 or 20, and the order is not fixed, sometimes a = 1 & B = 2 & c = 3, sometimes B = 2 & a = 1 & c = 3
How can I easily obtain the value of a parameter, for example, I want to obtain the value of c in it
I tried to use explode to interrupt the string, but I felt that it was a pretty good thing. Can I use other functions directly? share with me:
------ Solution --------------------
$s='a=1&b=2&c=3';
parse_str($s,$ar);
print_r($ar);
Array
(
[A] => 1
[B] => 2
[C] => 3
)
------ Solution --------------------
$s = 'a=1&b=2&c=3';
parse_str($s, $a);
print_r($a);
Array
(
[A] => 1
[B] => 2
[C] => 3
)