Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>No, there is not, for starters, it is impossible to have an array with elements sharing the same key</p> <pre><code>$x =array(); $x['foo'] = 'bar' ; $x['foo'] = 'baz' ; #replaces 'bar' </code></pre> <p>Secondarily, if you wish to merely prefix the numbers so that </p> <pre><code>$x[0] --&gt; $x['foo_0'] </code></pre> <p>That is computationally implausible to do without looping. No php functions presently exist for the task of "key-prefixing", and the closest thing is <a href="http://php.net/manual/en/function.extract.php" rel="nofollow noreferrer">"extract"</a> which will prefix numeric keys prior to making them variables. </p> <p>The very simplest way is this: </p> <pre><code>function rekey( $input , $prefix ) { $out = array(); foreach( $input as $i =&gt; $v ) { if ( is_numeric( $i ) ) { $out[$prefix . $i] = $v; continue; } $out[$i] = $v; } return $out; } </code></pre> <p>Additionally, upon reading XMLWriter usage, I believe you would be writing XML in a bad way. </p> <pre><code>&lt;section&gt; &lt;foo_0&gt;&lt;/foo_0&gt; &lt;foo_1&gt;&lt;/foo_1&gt; &lt;bar&gt;&lt;/bar&gt; &lt;foo_2&gt;&lt;/foo_2&gt; &lt;/section&gt; </code></pre> <p>Is not good XML. </p> <pre><code>&lt;section&gt; &lt;foo&gt;&lt;/foo&gt; &lt;foo&gt;&lt;/foo&gt; &lt;bar&gt;&lt;/bar&gt; &lt;foo&gt;&lt;/foo&gt; &lt;/section&gt; </code></pre> <p>Is better XML, because when intrepreted, the names being duplicate don't matter because they're all offset numerically like so: </p> <pre><code>section =&gt; { 0 =&gt; [ foo , {} ] 1 =&gt; [ foo , {} ] 2 =&gt; [ bar , {} ] 3 =&gt; [ foo , {} ] } </code></pre>
 

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