默认情况下,$arrDummy
其中已经有一些现有数据。
我想在现有的家庭中添加额外的家庭$arrDummy
通过调用getnewfamily()
,我会将多个小值添加到同一个姓氏中,然后返回主函数并添加到$arrDummy
.
我已经使用array_merge
and 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;
}