// An array to be encoded into a URL-encoded query string
$data = array(
    'name' => 'John Doe',
    'age' => 30,
    'city' => 'New York'
);

// Encode the array into a query string using http_build_query()
$queryString = http_build_query($data);
echo $queryString; // Output: name=John+Doe&age=30&city=New+York'

// Decode the query string using parse_str()
// Store the parsed data as an array in the second argument, $decodedArray
parse_str($queryString, $decodedArray);

print_r($decodedArray); // Output:  Array ( [name] => John Doe [age] => 30 [city] => New York )
parse_str(string $string, array &$result): void
$query_string = 'name=John+Doe&age=30';

// Discouraged: Omitting the array to store the result
parse_str($query_string);


// Variables $name and $age are created directly in the current scope
echo 'Name (Discouraged): ' . $name . '<br>'; // Output: 'Name (Discouraged): John Doe'
echo 'Age (Discouraged): ' . $age; // Output: 'Age (Discouraged): 30'
$query_string = 'name=John+Doe&age=30';

// Recommended: Store the result in the $parsed_data array
$parsed_data = []; // It's best to declare the array beforehand
parse_str($query_string, $parsed_data);

// The parsed data is now inside the $parsed_data array
$name = $parsed_data['name'];
$age = $parsed_data['age'];

echo 'Name (Recommended): ' . $name . '<br>'; // Output: 'Name (Recommended): John Doe'
echo 'Age (Recommended): ' . $age; // Output: 'Age (Recommended): 30'