默認情況下,$arrDummy
裏面已經有一些現有的數據。在現有的php關聯數組中添加更多數組
我想在更多的家庭加入到現有的$arrDummy
通過調用getnewfamily()
,我會添加多個小的值到同一個家族的名字,然後回到返回主功能,並添加到$arrDummy
。
我已經使用array_merge
和array_push
,在這裏和那裏測試,但事情沒有按預期工作。
$arrDummy= array(
"Family name aa" =>
array(
"123" => "some value",
"112223" => "some value",
),
"Family Jacky" =>
array(
"7856" => "some savalue",
"2354" => "some vcx",
)
);
$arrDummy= getnewfamily($arrDummy);
echo "<pre>";
print_r($arrDummy);
echo "</pre>";
function getnewfamily($arrDummy)
{
$familyname="my current family";
if($condition1==true)
{
$arrTest1= array($familyname =>
array(
"123" => "some value"
)
);
array_push($arrDummy[$familyname], $arrTest1);
}
if($condition2==true)
{
$arrTest2= array($familyname =>
array(
"456" => "some other value",
"88888" => "somes other value",
)
);
array_push($arrDummy[$familyname], $arrTest2);
}
if($condition3==true)
{
$arrTest3= array($familyname =>
array(
"756" => "further more"
)
);
array_push($arrDummy[$familyname], $arrTest3);
}
//How to merge or push to this very specific datas into $arrTest subarray?
return $arrDummy;
}
這是錯誤的'$ arrTest = array($ family =>());' – Baba