How to add missing elements from from two arrays to first array
<p>I am currently using SimpleXML to reading an xml file to generate my first array. This array displays a list of images that are found in a directory and written to xml file.</p>

<p>This has worked for me in the past until I upload new photos to the same album. I like to know what one does to get a complete list of images that got uploaded to the end of that first array. Any suggestions?</p>

<p>XML File:</p>

<pre><code>&lt;album&gt;
&lt;image path="/albums/1/images/100_4124.jpg" /&gt;
&lt;image path="/albums/1/images/100_4307.jpg" /&gt;
&lt;image path="/albums/1/images/100_4335.jpg" /&gt;
&lt;/album&gt;
</code></pre>

<p>SimpleXML to get array:</p>

<pre><code>$xml = simplexml_load_file('/albums/1/photos.xml');
foreach ($xml-&gt;image as $image)  {
    echo '&lt;li&gt;&lt;img src="'.$image.'"&gt;&lt;/li&gt;';
}
</code></pre>

<p>What I am getting for my results:</p>

<pre><code>&lt;li&gt;&lt;img src="/albums/1/images/100_4124.jpg"&gt;&lt;/li&gt;
&lt;li&gt;&lt;img src="/albums/1/images/100_4307.jpg"&gt;&lt;/li&gt;
&lt;li&gt;&lt;img src="/albums/1/images/100_4335.jpg"&gt;&lt;/li&gt;
</code></pre>

<p>Scanning the directory for all images:</p>

<pre><code>if ($handle = @opendir('/albums/1/')) {
    $filenames = array();
    while (false !== ($file = readdir($handle))) {
        $ext = substr($file, strrpos($file, '.') + 1);
        if ($file != '.' &amp;&amp; $file != '..') {
            $filenames[] = $file;
            $total++;
        }
    }
}
closedir($handle);

foreach ($filenames as $filename) {
    echo '&lt;li&gt;&lt;img src="'.$filename.'"&gt;&lt;/li&gt;';
}
</code></pre>

<p>What I would like to get for results using both arrays:</p>

<pre><code>&lt;li&gt;&lt;img src="/albums/1/images/100_4124.jpg"&gt;&lt;/li&gt;
&lt;li&gt;&lt;img src="/albums/1/images/100_4307.jpg"&gt;&lt;/li&gt;
&lt;li&gt;&lt;img src="/albums/1/images/100_4335.jpg"&gt;&lt;/li&gt;    

&lt;li&gt;&lt;img src="/albums/1/images/100_9000.jpg"&gt;&lt;/li&gt;
&lt;li&gt;&lt;img src="/albums/1/images/100_9001.jpg"&gt;&lt;/li&gt;
&lt;li&gt;&lt;img src="/albums/1/images/100_9002.jpg"&gt;&lt;/li&gt;
</code></pre>

<p>The last 3 images that are missing from xml file would be added it to the end of the list.</p>
