Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8369809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:44:55+00:00 2026-06-09T13:44:55+00:00

Look at this code: $a = array(‘1’=>’1’); $b = array(”=>”); var_dump(array_merge($a,$b)); the output seems

  • 0

Look at this code:

$a = array('1'=>'1');
$b = array(''=>'');

var_dump(array_merge($a,$b));

the output seems really strange to me:

array(2) {
  [0] =>
  string(1) "1"
  '' =>
  string(0) ""
}

Ok, I’ve changed $a into this: $a = array('k'=>'v'); and the output became more predictable:

array(2) {
  'k' =>
  string(1) "v"
  '' =>
  string(0) ""
}

The question is: why the hell the key of the first element is 0 in the first example?

edit:

var_dump($a);
array(1) {
  [1] =>
  string(1) "1"
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:44:57+00:00Added an answer on June 9, 2026 at 1:44 pm

    Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

    http://php.net/array_merge

    Yes, it’s an idiosyncrasy of PHP to treat numeric string values as numeric values in this case. You may want to use $a + $b instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Look please at this code: public static void main(String[] args) { String[] array =
Please look at this code: def chop(array, search): lo = 0 high = len(array)
I want to statically allocate the array. Look at the following code, this code
First look at this code: class Program { static void Main(string[] args) { var
Take a look at this code: public class Test { public static void main(String...
My array list somehow becomes populated. Look at this code: final ListView list =
Take a look at this code: $GET = array(); $key = 'one=1'; $rule =
Look at this code: $sql = $this->getAdapter()->select() ->from(array('mab' => 'module_adv_banner')) ->joinLeft(array('mafb' => 'module_adv_filebanner'),'mab.id =
look at this code, <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script> function change() {
Look at this code: class MyClass(): # Why does this give me NameError: name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.