I have a string that looks like:
single=Single&multiple=Multiple2&check=check1&radio=radio2
how could I create a array like this:
array(
'single' => 'Single',
'multiple' => 'Multiple2',
'check' => 'check1',
'radio' => 'radio2',
)
We can have an array with strings as its elements. Thus, we can define a String Array as an array holding a fixed number of strings or string values. String array is one structure that is most commonly used in Java. If you remember, even the argument of the 'main' function in Java is a String Array.
PHP | str_split() Function The str_split() is an inbuilt function in PHP and is used to convert the given string into an array.
Use parse_str
parse_str('single=Single&multiple=Multiple2&check=check1&radio=radio2', $data);
And in $data you will have your variables.
If this comes from an URL you can have this already as an array in the $_GET or $_POST variables. Otherwise use explode() to convert string to an array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With