i have two arrays
我有两个阵列
[id_price] => {"9":"1000.000","10":"2000.000"}
and the second one
第二个
[id_cur] => {"9":"USD","10":"USD"}
now i want to combine this two arrays using key values please check the below code you ill get some idea thank you.
现在我想用键值组合这两个数组请检查下面的代码你得到一些想法谢谢你。
$id_price = $_POST['id_price'];
$id_cur = $_POST['id_cur'];
$phpArray = json_decode($id_price, true);
$phpArray_2 = json_decode($id_cur, true);
foreach ($phpArray as $key => $value)
{
now here i need to get the
values of Currency and Price based on Key value (ID)
Example if ID(key) : 9 then $Currency = USD , $Price =1000.000
}
now i am getting out inside foreach
现在我要走出foreach
in this foreach $key =>9 , 10 etc.., $value => 1000.000 , 2000.000 etc..,
在这个foreach $ key => 9,10等..,$ value => 1000.000,2000.000等..,
but i need the $phparray_2 currency value also inside foreach now
但我现在也需要在foreach里面的$ phparray_2货币值
1 个解决方案
#1
$value
will contain the price and by using $key
you can also get the units from $phpArray_2
. But it is considered that the keys will be same and the values will be consistent. Try with -
$ value将包含价格,通过使用$ key,您还可以从$ phpArray_2获取单位。但是认为键将是相同的并且值将是一致的。尝试 -
foreach ($phpArray as $key => $value)
{
echo $value. ' '. $phpArray_2[$key];
}
#1
$value
will contain the price and by using $key
you can also get the units from $phpArray_2
. But it is considered that the keys will be same and the values will be consistent. Try with -
$ value将包含价格,通过使用$ key,您还可以从$ phpArray_2获取单位。但是认为键将是相同的并且值将是一致的。尝试 -
foreach ($phpArray as $key => $value)
{
echo $value. ' '. $phpArray_2[$key];
}