Ben içine değiştirmek gerekir:
$arr['id']=1;
$arr['type']=2;
Kullanın: parse_str().
void parse_str(string $str [, array &$arr])
Bu, geçerli kapsam içinde bir URL ve setleri değişkenler yoluyla geçirilen sorgu dizesi sanki str ayrıştırır.
Örnek:
<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first; // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
parse_str($str, $output);
echo $output['first']; // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz
?>
Eğer sadece kullanmak, bir sorgu dizesi gibi göründüğünü ayrıştırmak istediğiniz varsayarsak parse_str()
a>:
$input = 'id=1&type=2';
$out = array();
parse_str($input, $out);
print_r($out);
Çıktı:
Array
(
[id] => 1
[type] => 2
)
İsteğe bağlı ikinci parametre geçemez ve parse_str()
yerine geçerli kapsamı içine değişkenleri enjekte edecektir. Don't do this in the global scope. Ve ben bunu hiç yapmayın iddia edebilir. Bu register_globals()
kötü olduğunu, aynı nedenle bulunuyor.
Use parse_str()
with the second argument, bu gibi:
$str = 'id=1&type=2';
parse_str($str, $arr);
$arr
ardından içerecektir:
Array
(
[id] => 1
[type] => 2
)