i want to convert some Cookie Data into Array .
example
$cook = "lg=en; mi=ui; uo=lo; ri=ui";
I want to convert this data to array some thing like this :
Array (
'lg' => 'en',
'mi' => 'ui',
'uo' => 'lo',
'ri' => 'ui'
)
I want to convert $cook
data an array like that as a ouput .
Please , help me . Thanks
$cook = "lg=en; mi=ui; uo=lo; ri=ui";
foreach(explode("; ", $cook) as $v){
$tmp = explode("=", $v);
$return[$tmp[0]] = $tmp[1];
}
print_r($return);
If the cookie content is a pattern as value1<separator>value2<separator>value3
, you could use explode
function:
$array = explode($separator, $cook);
$arr1 = explode('; ',$cook);
$arr2 = array();
foreach($arr1 as $val)
{
list($a,$b) = explode('=',$val);
$arr2[$a] = $b;
}
ps: use meaningful variable names.
$a1=explode(";",$cook);
foreach($a1 as $a)
{
$b=explode("=",$a);
$arr[$b[0]]=$b[1];
}
$arr is your array
What about this: arr = "lg=en; mi=ui; uo=lo; ri=ui".split(';')
You should get rid of the extra spaces first