我需要重命名动态数组键,并创建一个新数组。这是给定的数组:
array(21)
{
["0161"] =>
array(5)
{
["L_NAME0161"] =>
string(13) "john%20Hewett"
["L_TRANSACTIONID0161"] =>
string(17) "50350073XN1446019"
["L_AMT0161"] =>
string(6) "8%2e50"
["L_FEEAMT0161"] =>
string(9) "%2d0%2e55"
["L_NETAMT0161"] =>
string(6) "7%2e95"
}
["08591"] =>
array(5)
{
["L_NAME08591"] =>
string(18) "Norbert%20Bendixen"
["L_TRANSACTIONID08591"] =>
string(17) "1WN98871MS4263823"
["L_AMT08591"] =>
string(6) "8%2e50"
["L_FEEAMT08591"] =>
string(9) "%2d0%2e55"
["L_NETAMT08591"] =>
string(6) "7%2e95"
}
}
这是我正在使用的代码,它对我不起作用:
foreach ($reb AS $newrebarray)
{
foreach ($newrebarray as $ke => $val)
{
if (preg_match("/L_NETAMT/i", $ke))
{
$newarrayreb1 = array('Net' => $val);
}
if (preg_match("/L_TRANSACTIONID/i", $ke))
{
$newarrayreb1 = array('TransactID' => $val);
}
if (preg_match("/L_NAME/i", $ke))
{
$newarrayreb1 = array('Name' => $val);
}
}
}
请注意,数组键是动态的,我想用静态键和相关值创建一个新数组。当我运行代码时,我得到了五个不同的数组。