I am trying to use array_map function to parse query string and get a key=>value pair:
function parse_query_string($string)
{
$result = [];
$arry = explode('&',$string);
$get_qry_str_array = function($str, &$result)
{
$a = explode('=',$str);
$result[$a[0]] = $a[1];
};
array_map($get_qry_str_array,$arry, $result);
return $result;
}
if i use this function as below i was expecting it would return an associative array with each query string parameter and value as key=>value pair because i am passing the $result variable as reference.
$qry_str_array = parse_query_string('edit=1&delete=2');
print_r($qry_str_array);
That is i am expecting an array like:
[
'edit' => 1,
'delete' => 2,
]
but i am getting an empty array.
Am i using this in a wrong way? I am new to php world, relatively.