title: Codeigniter 2.1, PHP - get random array from key value pair
body: <p>I have query from which I need to take random values (random rows) and limit to, lets say, 5 results and subtract them from main array (query). How can I do this?</p>
  
  <p>This is query function:</p>
  
  <pre><code>public function galerija_jedna_slike()
      {
          $galerija = $this-&gt;db-&gt;order_by('id_galerija', 'RANDOM')-&gt;limit(1)-&gt;get($this-&gt;table)-&gt;row();
          $q = " SELECT * FROM galerija_slike
                  LEFT JOIN galerije
                  ON galerija_slike.galerija_id = galerije.id_galerija
                  WHERE galerija_id = $galerija-&gt;id_galerija ";
          return $this-&gt;db-&gt;query($q)-&gt;result_array();
      }
  </code></pre>
  
  <p>I managed to get random values, and now I need to remove those values from the main array. Function:</p>
  
  <pre><code>function array_random_assoc($arr, $num = 1) {
          $keys = array_keys($arr);
          shuffle($keys);
  
          $r = array();
          for ($i = 0; $i &lt; $num; $i++) {
          $r[$keys[$i]] = $arr[$keys[$i]];
          }
          return $r;
      }
  </code></pre>