Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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/13.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 将关联数组添加到数组-如何?_Php_Arrays - Fatal编程技术网

Php 将关联数组添加到数组-如何?

Php 将关联数组添加到数组-如何?,php,arrays,Php,Arrays,我有一个数组结构,如下所示: $families = array ( "Griffin"=>array ( "Father" => "Peter", "Mother" => "Lois", "Child" => "Megan" ), "Brown"=>array ( "Father" => "Cleveland", "Mother" =&g

我有一个数组结构,如下所示:

$families = array
(
    "Griffin"=>array
    (
        "Father" => "Peter",
        "Mother" => "Lois",
        "Child" => "Megan"
    ),

    "Brown"=>array
    (
        "Father" => "Cleveland",
        "Mother" => "Loretta",
        "Child" => "Junior"
    )

);
我的问题是:

如何将另一个名为“辛普森一家”的数组添加到此结构中,并将“荷马”、“玛姬”和“巴特”作为数据


谢谢大家……

就像你们添加的
Griffin
和Brown一样。如果稍后在代码中执行此操作:

$families['Simpsons'] = array(
  'Father' => 'Homer', 
  'Mother' => 'Marge', 
  'Child'  => 'Bart'
);
 $families['Simpsons'] = array('Mother' => 'Marge','Father' =>'Homer','Child' => 'Bart');

与您添加的
Griffin
和Brown的方式相同。如果稍后在代码中执行此操作:

 $families['Simpsons'] = array('Mother' => 'Marge','Father' =>'Homer','Child' => 'Bart');

如何添加以前的元素?您尝试过什么?如何添加以前的元素?你试过什么?