- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
array(1) { ["second"]=> arra-6ren">
所以基本上我有这两个数组我想合并......
array(1) {
["first"]=>
array(1) {
["second"]=>
array(0) {
}
}
}
array(1) {
["second"]=>
array(1) {
["third"]=>
array(0) {
}
}
}
array(1) {
["first"]=>
array(1) {
["second"]=>
array(1) {
["third"]=>
array(0) {
}
}
}
}
$arr = array_merge_recursive($arr1, $arr2)
我得到这个输出:
array(2) {
["first"]=>
array(1) {
["second"]=>
array(0) {
}
}
["second"]=>
array(1) {
["third"]=>
array(0) {
}
}
}
最佳答案
数组在相同的“级别”上合并。您的数组不在同一级别重叠,一个顶级值为“first”,另一个为“second”。所以它会产生一个新的数组,其中两个数组都在顶层。
为了达到你想要的结果,你需要填写
array_merge_recursive($arr1['first'], $arr2)
array_merge_recursive
从那里。
关于PHP array_merge_recursive 不能如我所愿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2038542/
所以我想从一个文本文件动态构建一个多维数组,除了数字键让我感到困惑之外,一切都完美无缺...... 文本文件看起来像这样: a=1 b.c=2 b.d.0.e=3 b.d.0.f=4 b.d.1.e=
所以基本上我有这两个数组我想合并...... array(1) { ["first"]=> array(1) { ["second"]=> arra
我已经浏览了这里的帖子,但找不到任何似乎可以解决我的问题的内容。我对 PHP/MySQL 相当陌生,我似乎无法弄清楚为什么这个 array_merge_recursive 函数一直告诉我我的第一个数组
$array1 = [ '1' => '11', 'b' => 1, 3 => 33, 8 => 8 ]; $array2 = [ '1' => '22
$php -a php > $data1 = ['tag' => 'div', 'classes' => [1,2,3]]; php > $data2 = ['tag' => 'section', '
我正在为 PHP 中的数据结构而苦苦挣扎。我正在尝试使用 array_merge_recursive 通过类似的键来压缩数组,然后获取所有值而不是覆盖它们。这就是我选择 array_merge_rec
我只想合并 $a = array("59745506"=>array("up" => 0,)); $b = array("59745506"=>array("text" => "jfrj")); $c
php中array_merge_recursive函数用于将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面,返回作为结果的数组。本文章将详细介绍array_merge_recur
我有这个代码 $a1 = array( 'success' => TRUE, 'data' => array( 'foo' => ar
我尝试递归合并以下 2 个数组,这样我就不会丢失数据,但我也不希望重复任何数据。 $a = array( 'group1' => array( 'names' => array
是否有递归合并数组的方法,就像 PHP 的 array_merge_recursive() 函数一样,除了整数键被视为字符串键? (对于过程而言,键保持可解析为整数很重要。) 例如: $a = arr
我有一些默认配置,以及一些可配置的特定配置。我需要将特定配置合并到默认配置中。 在特定配置选项不存在的情况下, 将使用默认选项。 在 value 的情况下是标量,具体配置应该应用 在 value 的情
我是一名优秀的程序员,十分优秀!