title: PHP permutation multiple same elements
body: <p>I need a function which returns all possible combinations,</p>
  
  <p>e.g.</p>
  
  <p>chars = range('a', 'c');</p>
  
  <ol>
  <li>= a a a</li>
  <li>= a a b</li>
  <li>= a b a</li>
  <li>= a b b</li>
  <li>= a b c</li>
  <li>= a c b
  ...
  n. = c c c</li>
  </ol>
  
  <p>(order doesn't matter)</p>
  
  <p>and so on</p>
  
  <p>i got this </p>
  
  <pre><code>function pc_permute($items, $perms = array( )) {
      if (empty($items)) {
          $return = array($perms);
      }  else {
          $return = array();
          for ($i = count($items) - 1; $i &gt;= 0; --$i) {
               $newitems = $items;
               $newperms = $perms;
           list($foo) = array_splice($newitems, $i, 1);
               array_unshift($newperms, $foo);
               $return = array_merge($return, pc_permute($newitems, $newperms));
           }
      }
      return $return;
  }
  
  $p = pc_permute(array(0, 1, 2, 3));
  var_dump($p);
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/questions/5506888/permutations-all-possible-sets-of-numbers">Here</a></p>
  
  <p>But i wasn't able to figure out how to chance/rewrite this to get all possible combination with multiple same elements.</p>
  
  <p>Thanks, Mohammer</p>