title: How to fill a multidimensional array with values in php
body: <p>I am experimenting with datatables and php, and trying to get an example server side script working at <a href="https://www.datatables.net/examples/data_sources/server_side.html" rel="nofollow">https://www.datatables.net/examples/data_sources/server_side.html</a>.</p>
  
  <p>as part of this I need to create an array of arrays of the datatable columns that looks like:</p>
  
  <pre><code>$columns = array(
                    array( 'db' =&gt; 'first_name', 'dt' =&gt; 0 ),
                    array( 'db' =&gt; 'last_name',  'dt' =&gt; 1 ),
                    array( 'db' =&gt; 'position',   'dt' =&gt; 2 ),
                    array( 'db' =&gt; 'office',     'dt' =&gt; 3 ),
  
                );
  </code></pre>
  
  <p>I have an array:</p>
  
  <pre><code>$mytablescolumns = array('name1','name2', ... )
  </code></pre>
  
  <p>which I would like to iterate through producing a 2d array that looks like:</p>
  
  <pre><code> $columns = array(
                    array( 'db' =&gt; 'name1', 'dt' =&gt; 0 ),
                    array( 'db' =&gt; 'name2',  'dt' =&gt; 1 ),
  </code></pre>
  
  <p>I've looked at <a href="http://php.net/manual/en/function.array-fill.php" rel="nofollow">http://php.net/manual/en/function.array-fill.php</a> and <a href="http://php.net/manual/en/function.array-fill-keys.php" rel="nofollow">http://php.net/manual/en/function.array-fill-keys.php</a> , but I'm not sure if these will accomplish this since they appear to deal with 1D arrays. How can I accomplish this?</p>