Problem with values on a foreach loop and how can I assign the correct value to the correct variable
<p>I have a blog, and I am creating a script to show my posts (title-content-image) in another page. With the code below I get the first image of the post inside of <code>&lt;div class="entry"&gt;</code></p>

<p>The problem is : Imagine that I have 10 posts. Each of these has 1 title 1 content and images. Some of my posts do not have images at all. For example, the title of post 4 will be saved to variable "vartitles4", the content to "varcontents4" and the image to "varimages4". If post 4 does not have any images, it means that "varimages4" will have the value that was meant to be saved on "varimages5". (so varimages10 value will be null at the end)</p>

<p>So, how can I assign a value like a non-image.gif to varimages4 so that the script will work properly ?</p>

<p>Below is the code that gets the images. I have another two blocks of code like this one (title-content) before that.</p>

<pre><code>$img = $xPathimages-&gt;query('//div[@class="entry"]//img'); 
$thefirst = 1;
$iimg=0;
foreach ($img as $imgs) { 
$images = $imgs-&gt;getAttribute('src'); 
${'varimages' . $iimg} = $images; //the value is saved to varimages1/2/3/4/5/6...
if($thefirst == 1) break; //gets only the first image
$iimg=$iimg+1;
}
</code></pre>

<p>Thank you people!</p>
