Switching over from selecting multiple values from array to a single value in PHP
<p>I currently have a piece of code that is selecting multiple values from an array and was just wondering how I can switch it over to only picking a single value from an array. </p>

<p>So far I've tried changing <code>array_rand($status, rand(2,3))</code> to <code>array_rand($status, rand(1,1))</code> but it gives me the error message ** Invalid argument supplied for foreach()**. How can I resolve it?</p>

<pre><code>$dateStart = new DateTime();
$dateStart-&gt;setDate(2012, 10, 01);
$dateEnd = new DateTime();
$dateEnd-&gt;setDate(2012, 12, 01);

$dates = array();
while ( $dateStart &lt; $dateEnd ) {
   $rand = array_rand($status, rand(2,3));
   $text = '';
   foreach ( $rand as $key ) $text .= $status[$key] . '&lt;br /&gt;';

   printf("&lt;li&gt;&lt;div id='activity_date'&gt;%s&lt;/div&gt;
           &lt;div id='activity_box'&gt;
           &lt;div id='activity_text'&gt;" . $text . ' request&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;',

   $dateStart-&gt;format("d/m/Y")
   );

   $dateStart-&gt;modify(sprintf("+%d day",mt_rand(1, 10)));
}
</code></pre>
