title: PHP - How can I get rid of square bracket and index in array
body: <p>I am trying to create string associated with an object and create an array. Instead of having 0 =&gt; array:1, 1 =&gt;array:1, 2 =&gt;array:1. I want to have just &quot;orange&quot; =&gt; Option {}, &quot;mango&quot; =&gt; Option{},   &quot;banana&quot; =&gt; Option {} in an array as Array:5</p>
  <pre><code>array:5 [▼
    0 =&gt; array:1 [▼
      &quot;orange&quot; =&gt; Option {#76 ▼
        -name: &quot;american orange&quot;
        -botanical: &quot;citrus&quot;
        -year: &quot;1&quot;
        -color: &quot;orange&quot;
        -size: &quot;2&quot;
        -scope: &quot;season&quot;
        -choices: []
      }
    ]
    1 =&gt; array:1 [▼
      &quot;Mango&quot; =&gt; Option {#3098 ▼
        -name: &quot;american orange&quot;
        -botanical: &quot;&quot;
        -year: &quot;2&quot;
        -color: &quot;green&quot;
        -size: &quot;4&quot;
        -scope: &quot;season&quot;
        -choices: []
      }
    ]
    2 =&gt; array:1 [▼
      &quot;banana&quot; =&gt; Option {#3099 ▼
        -name: &quot;Billy&quot;
        -botanical: &quot;&quot;
        -year: &quot;1&quot;
        -color: &quot;dark&quot;
        -size: &quot;2&quot;
        -scope: &quot;season&quot;
        -choices: array:5 [▼
          &quot;&quot; =&gt; &quot;&quot;
          &quot;status&quot; =&gt; &quot;hard&quot;
          &quot;condition&quot; =&gt; &quot;ripe&quot;
          &quot;thickness&quot; =&gt; &quot;thick&quot;
          &quot;long&quot; =&gt; &quot;long&quot;
        ]
      }
    ]
  ]
  </code></pre>
  <p>This is my code, <strong>$options[] = [$resultKey =&gt; $option];</strong> This is where i am getting it wrong.  <strong>[$resultKey =&gt; $option]</strong> is the one creating an array. All I want is $resultKey =&gt; $option so that I can achieve <strong>&quot;Orange&quot; =&gt; Option{}</strong>. I tried $options[] = (object)[$resultKey =&gt; $option]; it is still displaying indices. as I only want pair values without indices. [&quot;Orange&quot; =&gt; Option{},  &quot;Mango&quot; =&gt; Option{}, &quot;Banana&quot; =&gt; Option{} ]</p>
  <pre><code> $options = [];
  
          foreach ($result as $resultKey =&gt; $resultValue) {
              $option = new Option($resultKey['scope'], $resultValue['name'], '', $resultValue['botanical'], $resultValue['year'], $resultValue['color'],  $resultValue['size'] !== 'choice' ? [] :$num[0]);
              $options[] = [$resultKey =&gt; $option];
             // dump([$resultKey =&gt; $option]);
          }
         ```
  </code></pre>