title: Ways of getting 20% of elements in array - PHP
body: <p>I have an array of n elements and I need to get random 20% of those elements into another array. Is there any function which can achieve this?</p>
  
  <p>Currently what I can think of is this:</p>
  
  <pre><code>foreach ($orders as $order) {
      if (rand(1, 100) &gt; 80) {
          echo('20%');
      } else {
          echo('80%');
      }
  }
  </code></pre>
  
  <p>Is there a more optimal way?</p>