title: Randomly pick array values, add them up, until you get a certain value in php
body: <p>I have the following array with undefined number of elements</p>
  
  <pre><code> $marks=array('2','4','9','3');
   target=50;
  </code></pre>
  
  <p>I want to randomly loop through the array, add up the values I fetch until the total is my target. </p>
  
  <pre><code> $total=0;        /////initialize total
   for($i=0;$i&lt;=sizeof($marks);++$i)
           {
         /////////Pick up random values add them up until $total==$target
         /////////return the new array with selected elements that sums up to 
         /////////target
           }
  </code></pre>
  
  <p>I hope my question is clear, also note that the loop should not iterate too many times since the elements might never add up to the total. I have tried adding the items in line but to no avail. Thanks in advance</p>