PHP array to jQuery options
<p>I'm creating a Wordpress Plugin which uses a jQuery script. I've created a PHP array which contains its options like:</p>

<p><code>$settings = array('setting1' =&gt; 'value1', 'setting2' =&gt; 'value2', 'setting3' =&gt; 10)</code></p>

<p>I was now going to use foreach to loop over the items and print them like this:</p>

<pre><code>foreach($settings as $setting =&gt; $value) {

if (is_string($value)) { $value = "'" . $value . "'"; }
$output .= $setting . ':' . $value .',';
</code></pre>

<p>}</p>

<p>which should make me end up with:</p>

<pre><code>(window).load(function() {
$('#widget').myWidget({
    setting1:'value1', 
    setting2:'value2', 
    setting3:10})
</code></pre>

<p>With the current setup I end up with the last entry having a ',' at the end (one too many) which means I get a Javascript error, so I need to remove it.</p>

<p>All with all, I have the feeling I'm doing something very dirty (including the is_string check) and I was wondering if there is a neat way to deal with this?</p>
