Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I'm passing through a string via ajax to be used with PHP.
Example
home?area=Ohio&country=United%20States
How can I end up with an array that looks like the following?
array('area' => 'ohio', 'country' => 'United States');
$_GET
parse_str
parse_url
Assuming you're using the current request's query string, try:
parse_str($_SERVER['QUERY_STRING'], $output); echo $output['area']; // Ohio
Add a comment
parse_str("area=Ohio&country=United%20States");
https://www.php.net/manual/en/function.parse-str.php
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
$_GET?parse_str, possibly in tandem withparse_urlif you have an entire url and you need to seperate the query string out of it.