Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your array is not constructed properly. You have duplicate key names, so they will be overwritted.</p> <p>Let's say you have:</p> <pre><code>$json[] = array( 'value' =&gt; 'x', 'label' =&gt; 'x-y', 'value' =&gt; 'y', 'label' =&gt; 'y-x' ); var_dump($json); </code></pre> <p>The output is:</p> <pre><code>array (size=1) 0 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) </code></pre> <p>Even <code>[]</code> in $json, doesn't automatically make you to have <code>0=&gt;array(x,y),1=&gt;array(y,x)</code>, you need to specify the keys.</p> <p>Because I don't know how many rows the MySQL is returning, my example will be with static while loop:</p> <pre><code>$max=5; //max iterations $i = 0; //first key $k = $max+1; //second key while ($i&lt;=$max) { $json[$i] = array( 'value' =&gt; 'x', 'label' =&gt; 'x-y' ); $json[$k] = array( 'value' =&gt; 'y', 'label' =&gt; 'y-x' ); $i++; $k++; } ksort($json); //this line is only to return the array sorted by keys asc, not necessary, for the testing purpose var_dump($json); </code></pre> <p>The second key <code>$k</code> should never be equal to <code>$i</code>, that's why I use the maximum $i can reach, to starting point of <code>$k</code>. Output:</p> <pre><code>array (size=12) 0 =&gt; array (size=2) 'value' =&gt; string 'x' (length=1) 'label' =&gt; string 'x-y' (length=3) 1 =&gt; array (size=2) 'value' =&gt; string 'x' (length=1) 'label' =&gt; string 'x-y' (length=3) 2 =&gt; array (size=2) 'value' =&gt; string 'x' (length=1) 'label' =&gt; string 'x-y' (length=3) 3 =&gt; array (size=2) 'value' =&gt; string 'x' (length=1) 'label' =&gt; string 'x-y' (length=3) 4 =&gt; array (size=2) 'value' =&gt; string 'x' (length=1) 'label' =&gt; string 'x-y' (length=3) 5 =&gt; array (size=2) 'value' =&gt; string 'x' (length=1) 'label' =&gt; string 'x-y' (length=3) 6 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) 7 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) 8 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) 9 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) 10 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) 11 =&gt; array (size=2) 'value' =&gt; string 'y' (length=1) 'label' =&gt; string 'y-x' (length=3) </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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