我有像
这样的数据 list=7251270233&total_amount=28841.28&r_g_amount=1800&cash=1000&credit=500&bank=300&bank_from=abc&bank_to=pqr
使用array
将其转换为explode
并获得
0:"list=7251270233"
1:"total_amount=28841.28"
2:"r_g_amount=1800"
3:"cash=1000"
4:"credit=500"
5:"bank=300"
6:"bank_from=abc"
7:"bank_to=pqr"
现在我将它转换为key->value
中的数组,如:
array("list"=>"7251270233",
"total_amount"=>"28841.28",
"r_g_amount"=>"1800",
"cash"=>"1000",
"credit"=>"500",
"bank"=>"300",
"bank_from"=>"abc",
"bank_to"=>"pqr")
那我怎么能在数组中转换
答案 0 :(得分:1)
如下所示:
$query_string = "list=7251270233&total_amount=28841.28&r_g_amount=1800&cash=1000&credit=500&bank=300&bank_from=abc&bank_to=pqr";
$data_array = parse_str($query_string, $output);
print_r($output);
输出将如下:
Array
(
[list] => 7251270233
[total_amount] => 28841.28
[r_g_amount] => 1800
[cash] => 1000
[credit] => 500
[bank] => 300
[bank_from] => abc
[bank_to] => pqr
)
答案 1 :(得分:0)
<?php
$str = 'list=7251270233&total_amount=28841.28&r_g_amount=1800&cash=1000&credit=500&bank=300&bank_from=abc&bank_to=pqr';
$strarr = explode('&',$str);
print_r($strarr);
foreach($strarr as $stra){
$result[explode('=',$stra)[0]] = explode('=',$stra)[1];
}
print_r($result);
输出
Array
(
[list] => 7251270233
[total_amount] => 28841.28
[r_g_amount] => 1800
[cash] => 1000
[credit] => 500
[bank] => 300
[bank_from] => abc
[bank_to] => pqr
)