php function - how to make dynamic with a query <p>How can I take a function which creates a metabox with a dropdown of hard coded values ("Hard", Soft" and "None") and make it create the metabox dynamically according to a given array of strings?</p> <p>Original function:</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>function your_prefix_product_fields( $meta_boxes ) { $meta_boxes[] = array( 'title' =&gt; __( 'Product Fields', 'your-prefix' ), 'post_types' =&gt; array( 'product', ), 'fields' =&gt; array( array( 'name' =&gt; __( 'Package', 'test' ), 'id' =&gt; 'package', 'type' =&gt; 'select', 'clone' =&gt; false, 'options' =&gt; array( 'Soft' =&gt; __( 'Soft', 'test' ), 'Hard' =&gt; __( 'Hard', 'test' ), 'None' =&gt; __( 'None', 'test' ), ), 'multiple' =&gt; true, 'std' =&gt; 'none', 'placeholder' =&gt; __( 'Select Package', 'test' ), ), ) ); return $meta_boxes; }</code></pre> </div> </div> </p> <p>I have the array: <code>["Hard", "Soft", "None"]</code></p> <p>EDIT: I thought more about my question and perhaps I can make it more clear:</p> <p>What I want to do is create this array dynamically from a query output:</p> <pre><code>'options' =&gt; array( 'Soft' =&gt; __( 'Soft', 'test' ), 'Hard' =&gt; __( 'Hard', 'test' ), 'None' =&gt; __( 'None', 'test' ), ), </code></pre> <p>Additional Questions:</p> <p>1) If I can create the 'options array' manually, can I write something like:</p> <pre><code>'options' =&gt; $packages, </code></pre> <p>given that I was able to create the array packages so that it will look like:</p> <pre><code>array( 'Soft' =&gt; __( 'Soft', 'test' ), 'Hard' =&gt; __( 'Hard', 'test' ), 'None' =&gt; __( 'None', 'test' ), ), </code></pre> <p>2) How can I create this type of array? Is it a hash map?</p> <p>I tried something like:</p> <pre><code>$packages['Soft'] = ('Soft', 'test'); </code></pre> <p>With no luck... What is the syntax for it?</p>