- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
array("up" => 0,)); $b = array("59745506"=>array("text" => "jfrj")); $c-6ren">
我只想合并
$a = array("59745506"=>array("up" => 0,));
$b = array("59745506"=>array("text" => "jfrj"));
$c = array_merge_recursive_new($a, $b);
结果:
Array
(
[0] => Array
(
[up] => 0
)
[1] => Array
(
[text] => jfrj
)
)
预期结果:
Array
(
[59745506] => Array
(
[up] => 0
[text] => jfrj
)
)
http://www.php.net/manual/en/function.array-merge-recursive.php 中的第二条评论正在工作,它是我的情况的最佳解决方案吗(我需要合并具有多个数字键和 2 个级别的数组)?
另一种解决方法是使用 array_map(function ()...
最佳答案
array_replace_recursive()
功能看起来正是您所需要的。
$a = array("59745506" => array("up" => 0,));
$b = array("59745506" => array("text" => "jfrj"));
$c = array_replace_recursive($a, $b);
var_export($c);
// array (
// 59745506 =>
// array (
// 'up' => 0,
// 'text' => 'jfrj',
// ),
// )
关于php array_merge_recursive 保留数字键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12051782/
所以我想从一个文本文件动态构建一个多维数组,除了数字键让我感到困惑之外,一切都完美无缺...... 文本文件看起来像这样: 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 的情
我是一名优秀的程序员,十分优秀!