Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP array_merge() function
    primarykey
    data
    text
    <p>I have some problems during working with <code>arrays</code> using <code>array_merge function</code>. Here an example:</p> <p><strong>First example:</strong></p> <pre><code> $first = array('01' =&gt; 1, '03' =&gt; 73); $second = array('14'=&gt;11, '15' =&gt; 23); var_dump(array_merge($first, $second)); </code></pre> <p>Result is:</p> <pre><code>array(4) { ["01"]=&gt; int(1) ["03"]=&gt; int(73) [0]=&gt; int(11) [1]=&gt; int(23) } </code></pre> <p>Expected:</p> <pre><code>array(4) { ["01"]=&gt; int(1) ["03"]=&gt; int(73) [14]=&gt; int(11) [15]=&gt; int(23) } </code></pre> <p><strong>Second example:</strong></p> <pre><code> $first = array('01'=&gt;3, '03'=&gt;10); $second = array('05'=&gt;44, '07'=&gt;3); var_dump(array_merge($first,$second)); </code></pre> <p>Result is(as expected):</p> <pre><code>array(4) { ["01"]=&gt; int(3) ["03"]=&gt; int(10) ["05"]=&gt; int(44) ["07"]=&gt; int(3) } </code></pre> <p><strong>Third example:</strong></p> <pre><code>var_dump(array_merge(array("somekey"=&gt; array("some value")))); </code></pre> <p>Result is(as expected):</p> <pre><code>array(1) { ["somekey"]=&gt; array(1) { [0]=&gt; string(10) "some value" } } </code></pre> <p><strong>Fourth example:</strong></p> <pre><code>var_dump(array_merge(array("34"=&gt; array("some value")))); </code></pre> <p>Result is:</p> <pre><code>array(1) { [0]=&gt; array(1) { [0]=&gt; string(10) "some value" } } </code></pre> <p>Expected:</p> <pre><code>array(1) { [0]=&gt; array(1) { ["34"]=&gt; string(10) "some value" } } var_dump(array_merge(array("34"=&gt; array("some value")))); </code></pre> <p>As you can see from <code>third</code> and <code>fourth</code> examples I set string for keys but the result was not as expected. </p> <p>What is wrong or incorrect of understanding? Thanks for helping.</p> <p><strong>Edited.</strong> Why (example first and second) the result is different, but the keys are string and consist of only with digest?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload