title: PHP how to quote string array values
body: <p>If I have the following array <code>$array[0] = array(
      "1" =&gt; bar,
      "2" =&gt; foo,
      "3" =&gt; 13546
  );</code> and I implode() it, the value that is returned will be: <code>bar,foo,13546</code> which cannot be used in a mysql query... How can I place single quotes just to those values that are strings...</p>
  
  <p>I've tryed a couple of ways (like <code>foreach($array as $key=&gt;$value)</code> to check with is_numeric() the $value, and the check is ok but I dont know how to change the value to '$value'...)</p>
  
  <p>Any toughts on this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I found another way to do this for those of you who are interested:</p>
  
  <pre><code>$result[0] = array(
      "1" =&gt; bar,
      "2" =&gt; foo,
      "3" =&gt; 1232.13
  );
  
  $copy_r = $result[0];
  
  foreach($copy_r as $key=&gt;$value)
  {
      if(!is_numeric($value))
      {
          $insert_array[] = "`$key` = '$value'";
      }
      else
      {
          $insert_array[] = "`$key` = $value";
      }
  }
  
  $final_string = implode(',', $insert_array);
  $insert_q = "INSERT INTO `table_name` SET $final_string
               ON DUPLICATE KEY UPDATE ($final_string)";
  </code></pre>