title: Building an array from a function
body: <p>I need to run the following function on every single page of a website:</p>
  
  <pre><code>&lt;?php 
  foreach ($page as $key =&gt; $item) 
  if ($page[$key][4] == basename(__DIR__)) 
      echo $page[$key][0] . " " . $page[$key][1] . " " . $page[$key][2] . " " . $page[$key][3] . " " . $page[$key][4];
  ?&gt;
  </code></pre>
  
  <p>I would like to retrieve the strings / variables / in an array so it can be used in the page in a dynamic fashion. Something like showing below:</p>
  
  <pre><code>&lt;?php 
  $result = array(
  'val0' =&gt; " ",      // Value from $page[$key][0]
  'val1' =&gt; " ",      // Value from $page[$key][1]
  'val2' =&gt; " ",      // Value from $page[$key][2]
  'val3' =&gt; " ",      // Value from $page[$key][3]
  'val4' =&gt; " "       // Value from $page[$key][4]
  );
  ?&gt;
  </code></pre>
  
  <p>I've looked for something like this everywhere. How can that be done?</p>