php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #18075 array_merge() redefines numeric keys
Submitted: 2002-06-30 16:14 UTC Modified: 2002-07-02 16:04 UTC
From: nepto at pobox dot sk Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.1.2 OS: Linux, FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nepto at pobox dot sk
New email:
PHP Version: OS:

 

 [2002-06-30 16:14 UTC] nepto at pobox dot sk
Lets consider that we have following arrays, $ar1 and $ar2:

// first array
$ar1 = array();
$ar1[1] = 'val1';
$ar1[2] = 'val2';

// second array
$ar2 = array('key' => '');

Than we have resulting array $res. Let's lookwhat happend after array_merge() call:

$res = array_merge($ar1, $ar2);
var_dump($res);

Resulting array is described here:

array(3) {
  [0]=>
  string(4) "val1"
  [1]=>
  string(4) "val2"
  ["key"]=>
  string(0) ""
}

Numeric keys 1 and 2 was recoded to 0 and 1. Looks like bug, isn't it?

I refer to the documentation, but there is nothing written about the numeric keys redefining. An exaple there (in documentation) shows example, where only numeric keys started from 0 are used, so no such change happened.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-30 17:22 UTC] derick@php.net
But it is a documentation problem... reclassifying
 [2002-07-02 16:04 UTC] eru@php.net
See example 2 on the manual-page, the sentence after the first code-box: "Don't forget that numeric keys will be renumbered!"

The next sentence reads: "If you want to completely preserve the arrays and just want to append them to each other, use the + operator."

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC