title: How to make a php array of a mysql_fetch_array while loop
body: <p>At the moment I have a large number of php files, each one with an array statement in the format:</p>
  
  <pre><code>$array1 = array ( array ( 'Husband' =&gt; 'bob',
                            'Wife' =&gt; 'ann' ),
                    array ( 'Husband' =&gt; 'fred',
                            'Wife' =&gt; 'donna' ),
                    array ( 'Husband' =&gt; 'john',
                            'Wife' =&gt; 'mary' ) ); 
  </code></pre>
  
  <p>This of course returns from <code>print_r ($array1)</code> the output (A):</p>
  
  <pre><code>    Array ( [0] =&gt; Array (
                    [Husband] =&gt; bob [Wife] =&gt; ann ) 
             [1] =&gt; Array ( 
                    [Husband] =&gt; fred [Wife] =&gt; donna ) 
             [2] =&gt; Array ( [Husband] =&gt; john [Wife] =&gt; mary ) )
  </code></pre>
  
  <p>In a separate class file, I access $array1 data, using statements like:</p>
  
  <pre><code>for ($col = 0; $col &lt; sizeof($array1); $col++)
  {
    echo $array[$col]['Wife']."&lt;br /&gt;";
  }
  </code></pre>
  
  <p>On the theory that a large number of anything is a database, I am wanting to migrate the data in the multiple php array files array into a MySQL database, and access the MySQL data from my class file.  So I set up the following in MySQL:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `arrays` (
    `id` int(5) NOT NULL auto_increment,
    `husband` varchar(255) collate utf8_unicode_ci NOT NULL,
    `wife` varchar(255) collate utf8_unicode_ci NOT NULL,
    PRIMARY KEY  (`id`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
  
  INSERT INTO `arrays` (`id`, `husband`, `wife`) VALUES
  (1, 'bob', 'ann'),
  (2, 'fred', 'donna'),
  (3, 'john', 'mary');
  </code></pre>
  
  <p>Then I access this MySQL database from PHP:</p>
  
  <pre><code>$sql = "SELECT * FROM `database`.`arrays`";
  $link  = mysql_connect ('localhost', 'username', 'password' ) or die(mysql_error());
  mysql_select_db ('database', $link) or die(mysql_error());
  $result = mysql_query ($sql) or die(mysql_error());
  while($row = mysql_fetch_array($result))
  {
    $array2 = array ( 'Husband' =&gt; $row['husband'],
                      'Wife' =&gt; $row['wife'] );
    print_r ($array2);
  }
  </code></pre>
  
  <p>This will produce output (B) like:</p>
  
  <pre><code>Array ( [Husband] =&gt; bob [Wife] =&gt; ann ) 
  Array ( [Husband] =&gt; fred [Wife] =&gt; donna ) 
  Array ( [Husband] =&gt; john [Wife] =&gt; mary )
  </code></pre>
  
  <p>My question is how do I make a php array of the mysql_fetch_array while loop, so that output B looks like output A.  I want to be able to continue to access the data in my class file in the manner <code>$array[$col]['Wife']</code>, but from the MySQL database.</p>