我正在以以下格式生成多维数组:
Array (
[0] => Array (
[UAM 355T] => Array ([v1] => 1000 ) )
[1] => Array (
[UAM 355T] => Array ( [v2] => 2000 ) )
[2] => Array (
[UAP 702X] => Array ( [v3] => 3000 ) )
[3] => Array (
[UAP 702X] => Array ( [v4] => 4000 ) )
)
使用php脚本:
$p = 0;
while($p < $entries[$i])
{
$garage_record[] = array( $license[$i]=> array( $details[$p] => $cost[$p]));
$p++;
}
print_r($garage_record);
虽然我希望它是一个二维数组,其中牌照链接到表单中的多个条目;
Array (
[UAM 355T] => Array ([v1] => 1000 ),
([v2] => 2000))
[UAP 702X] => Array(([v1] => 1000 ),
([v2] => 2000))
)
由于
答案 0 :(得分:1)
这是基本的数组操作,你可以实现你想做的事情:
$p = 0;
while($p < $entries[$i])
{
if (!isset($garage_record[$license[$i]]))
$garage_record[$license[$i]] = array();
$garage_record[$license[$i]][$details[$p]] = $cost[$p];
$p++;
}
print_r($garage_record);
答案 1 :(得分:0)
你可能正在寻找这样的东西:
foreach($records as $recordkey => $recordvalue) {
foreach($recordkey as $subrecord) {
$result[$recordkey][] = $subrecord;
}
}
print_r($result);