Pass element IDs into an array for POST form process
<p>So say I've got a series of images created with a php loop -></p>

<pre><code>&lt;img src="http://..._1.jpg" class="profile-thumb" id="12345678"&gt;
&lt;img src="http://..._2.jpg" class="profile-thumb" id="12345677"&gt;
&lt;img src="http://..._3.jpg" class="profile-thumb" id="12345676"&gt;
</code></pre>

<p>The user can select the image elements by clicking on them jquery style a la -></p>

<pre><code>    $(".profile-thumb").click(function () {
        if ($(this).hasClass("active")) {
            $(this).removeClass('active');
        } else {
            $(this).addClass('active');
        }
    });
</code></pre>

<p>So that when you click an image it adds an '.active' class to the image element -></p>

<pre><code>&lt;img src="http://..._3.jpg" class="profile-thumb active" id="12345676"&gt;
</code></pre>

<p>How would I pass all the selected elements IDs into an array for use in a form process with PHP?</p>

<p><strong>User journey:</strong></p>

<p>Click photo -> Adds ID to array -> Click a submit button -> Uses POST array to perform a function with all IDs (e.g. send an email to all users using the IDs identified as active)</p>

<hr>

<p>I want to pass the array to a loop with an AJAX call and echo output to the #post-info div -></p>

<pre><code>    $.get('post.php', function(data) {
        $('#post-info').html(data);
    });
</code></pre>

<p>How will I then read the POST array with a foreach loop?</p>

<hr>

<p><strong>Solution:</strong></p>

<p><strong>HTML:</strong></p>

<pre><code>&lt;button id="share" class="off"&gt;
    &lt;span&gt;Sharer&lt;/span&gt;
&lt;/button&gt;
&lt;div id="sharer"&gt;
&lt;!-- Array will echo here --&gt;
&lt;/div&gt;
</code></pre>

<p><strong>Javascript:</strong></p>

<pre><code>    $("#share").click(function () {
        //Create var array
        var list = $('.active-profile').map(function(){return this.id;}).toArray();

        $.post('sharer.php', {ids:list}, function(data) {
            $('#sharer').html(data);
        });

    });
</code></pre>

<p><strong>PHP (sharer.php)</strong></p>

<pre><code>        foreach ($_POST['ids'] as $id) {
            echo 'ID: ';
            echo $id;
        }
</code></pre>

<p>The javascript array (list) is sent via jquery POST and echo'd in the #sharer div</p>
