Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 添加动态键=>;3级数组选项中的值选项_Php_Arrays - Fatal编程技术网

Php 添加动态键=>;3级数组选项中的值选项

Php 添加动态键=>;3级数组选项中的值选项,php,arrays,Php,Arrays,我的代码中有一个数组作为主要选项 在这种情况下,我想将DynamicKey=>值添加到特定的选项数组键中 这是我的主要选项阵列: $configarray1 = array( "name" => "Addon", "description" => "module for whmcs", "version" => "1.1", "author" => "Me", "language" => "english", "fie

我的代码中有一个数组作为主要选项

在这种情况下,我想将DynamicKey=>值添加到特定的选项数组键中

这是我的主要选项阵列:

$configarray1 = array(
    "name" => "Addon",
    "description" => "module for whmcs",
    "version" => "1.1",
    "author" => "Me",
    "language" => "english",
    "fields" => array(
        "sender" => array (
            "FriendlyName" => "Sender", 
            "Type" => "dropdown", 
            "Options" => strtolower($GatewaysIM), 
            "Description" => $getBalance, 
            "Default" => $Defaultsender, 
        ),
        "validateday" => array (
            "FriendlyName" => "Days for Re-validation", 
            "Type" => "text", 
            "Size" => "25",
            "Description" => "", 
            "Default" => "90",
        ),
    )    
);
我想在configarray1字段键中添加此发件人阵列选项:

if($sender == 'sender1'){
        $configarray2['fields'] = array(
            "username" => array (
                "FriendlyName" => "username", 
                "Type" => "text", 
                "Size" => "25",
                "Description" => "", 
                "Default" => "", 
            ),
            "password" => array (
                "FriendlyName" => "password", 
                "Type" => "password", 
                "Size" => "25",
                "Description" => "", 
                "Default" => "", 
            )
        );
} elseif($sender == 'sender2'){
        $configarray2['fields'] = array(
            "line" => array (
                "FriendlyName" => "line", 
                "Type" => "text", 
                "Size" => "25",
                "Description" => "", 
                "Default" => "", 
            )
        );
}
当发送方为发送方1时,输出数组必须如下所示:

$configarray = array(
    "name" => "Addon",
    "description" => "module for whmcs",
    "version" => "1.1",
    "author" => "Me",
    "language" => "english",
    "fields" => array(
        "sender" => array (
            "FriendlyName" => "Sender", 
            "Type" => "dropdown", 
            "Options" => strtolower($GatewaysIM), 
            "Description" => $getBalance, 
            "Default" => $Defaultsender, 
        ),
        "username" => array (
            "FriendlyName" => "username", 
            "Type" => "text", 
            "Size" => "25",
            "Description" => "", 
            "Default" => "", 
        ),
        "password" => array (
            "FriendlyName" => "password", 
            "Type" => "password", 
            "Size" => "25",
            "Description" => "", 
            "Default" => "", 
        ),
        "validateday" => array (
            "FriendlyName" => "Days for Re-validation", 
            "Type" => "text", 
            "Size" => "25",
            "Description" => "", 
            "Default" => "90",
        ),
    )    
);
我测试了数组推送,但这首先在数组中添加了一个键,而不是在“字段”键中,我的代码是$configarray=array\u推送($configarray1,$configarray2);但这不管用

我还测试了两个数组的总和($configarray=$configarray1+$configarray2),但这与array_push相同,并为我返回了错误的输出


我怎样才能解决这个问题

你应该申报一下。您不需要新的变量

假设原始数组名为$configarray1,只需:

if($sender == 'sender1'){
    $configarray1['fields']['username'] = array(
        "FriendlyName" => "username", 
        "Type" => "text", 
        "Size" => "25",
        "Description" => "", 
        "Default" => "", 
   );
   $configarray1['fields']['password'] => array(
        "FriendlyName" => "password", 
        "Type" => "password", 
        "Size" => "25",
        "Description" => "", 
        "Default" => "", 
   );
} elseif($sender == 'sender2'){
   $configarray1['fields']['line'] = array (
        "FriendlyName" => "line", 
        "Type" => "text", 
        "Size" => "25",
        "Description" => "", 
        "Default" => "", 
  );
}

谢谢你@subzeta。不幸的是,这不起作用!输出仅为configarray1。