0

デフォルトでは、$arrDummyすでにその中にいくつかの既存のデータがあります。

既存のファミリに追加のファミリを追加したい$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;
}
4

1 に答える 1

0

あなたのスクリプトには非常に多くのエラーがあります

試す

$arrDummy = array(
"Family name aa" => array("123" => "some value","112223" => "some value"),
"Family Jacky" => array("7856" => "some savalue","2354" => "some vcx"));

$arrFamilytoAddtoDummy = getnewfamily($arrDummy,2);

var_dump($arrFamilytoAddtoDummy);

関数

function getnewfamily($arrDummy, $condition) {
    switch ($condition) {
        case 1 :
            $arrDummy["my current family"] = array("123" => "some value");
            break;
        case 2 :
            $arrDummy["my current family"] = array("456" => "some other value","88888" => "somes other value");
            break;
        case 3 :
            $arrDummy["my current family"] = array("756" => "further more");
            break;
    }

    return $arrDummy;
}

出力

array
  'Family name aa' => 
    array
      123 => string 'some value' (length=10)
      112223 => string 'some value' (length=10)
  'Family Jacky' => 
    array
      7856 => string 'some savalue' (length=12)
      2354 => string 'some vcx' (length=8)
  'my current family' => 
    array
      456 => string 'some other value' (length=16)
      88888 => string 'somes other value' (length=17)
于 2012-09-29T16:42:55.703 に答える