title: Create an associative array in php with dynamic key and value
body: <p>I want to create an associative array in php with dynamic key and also a dynamic value from a particular mysql table.</p>
  
  <p>The table name is <code>monthly_salary</code> with a two column named <code>month</code> and <code>salary</code> respectively.</p>
  
  <p>I get the data inside it:</p>
  
  <pre><code>$sql = mysql_query('SELECT * FROM monthly_salary');
  $sql2 = mysql_query('SELECT * FROM monthly_salary');
  </code></pre>
  
  <p>Then assigned and concatenated the collected data to <code>$mon</code> and <code>$sal</code>:</p>
  
  <pre><code>$mon = "";
  $sal = "";
  while($row = mysql_fetch_array($sql)){
      $mon .= $row['month'].", ";
  }
  while($row = mysql_fetch_array($sql2)){
      $sal .= $row['salary'].", ";
  }
  </code></pre>
  
  <p>After that I've converted it to array and concatenate it until it became and associative array:</p>
  
  <pre><code>$monArray = array(substr(trim($mon), 0, -1));
  $salArray = array(substr(trim($sal), 0, -1));
  $key = "";
  $keyWithVal = "";
  foreach($monArray  as $k){
      $key .= $k." =&gt; ";
  }
  foreach($salArray  as $k){
      $keyWithVal .= $key.$k.",";
  }
  
  $associativeArray = array(substr(trim($keyWithVal), 0, -1));
  </code></pre>
  
  <p>My Problem is that when I've echo it the result is always like this
  <strong>3500=>Jan=>3500</strong>:</p>
  
  <pre><code>foreach($associativeArray  as $k =&gt; $id){
      echo $k."=&gt;".$id;
  }
  </code></pre>
  
  <p>So how can I fix it and with the correct output <strong>Jan=>3500</strong>?</p>