PHP sort array by appearance
<p>I have array that need to sort by their appearance, as they are written manually as my free will. Note the values are hints to be expected to appear:</p>

<pre><code>  $options = array("the array retrieved from some forms");
  $items   = array();
  foreach ($options as $key =&gt; $val) {
    switch ($key) {
      case 'three':
        $items[]          = "this should come first";
        $items[]          = "now the second in order";
        $items[]          = "the third";
        $items[]          = "forth";

        switch ($val) {
          case 'a':
          case 'b':
            $items[]       = "fifth";
            $items[]       = "should be six in order";
            break;

          case 'c':
          default:
            $items[]    = "7 in order";
            break;
        }

        break;
</code></pre>

<p>...............</p>

<p>As you see the values can be anything, but what I need is to just implode and display the items based on their appearance. Its all manual order, what come first should be printed at top.</p>

<p><strong>Expected:</strong></p>

<pre><code>"this should come first";
"now the second in order";
"the third";
"forth";
"fifth";
"should be six in order";
"7 in order";
</code></pre>

<p><strong>Current unexpected:</strong></p>

<pre><code>"should be six in order";
"forth";
"7 in order";
"the third";
"fifth";
"this should come first";
"now the second in order";
</code></pre>

<p>But I can't seem to apply any of sorting from this <a href="http://www.php.net/manual/en/array.sorting.php" rel="nofollow">http://www.php.net/manual/en/array.sorting.php</a>
I suspect those $items are ordered somewhere by the forms which I have no way to reorder. I just have power to write output and order as I want from top to bottom. But I can't inset keys into $items, simply because I need to reorder freely.</p>

<p>I took a look at the output, the keys are not sorted as expected.</p>

<p>Any hint is very much appreciated. Thanks</p>
