Is the order of an associative array guaranteed in PHP?
<p>When I perform a foreach loop over an associatve array in php, the order in which it is performed is the order in which it is defined.</p>

<p>For example:</p>

<pre><code>$arr = array("z" =&gt; "z", "a" =&gt; "a", "b" =&gt; "b");

foreach($arr as $key =&gt; val)
  print("$key: $val\n");
</code></pre>

<p>Outputs:</p>

<pre><code>z: z
a: a
b: b
</code></pre>

<p>Whereas</p>

<pre><code>$arr = array("a" =&gt; "a", "b" =&gt; "b", "z" =&gt; "z");
</code></pre>

<p>Outputs:</p>

<pre><code>a: a
b: b
z: z
</code></pre>

<p>So my question is then: is this behavior defined at a specification level? Can I have reasonable certainty that this behavior will not be changed in future versions of PHP?</p>
