title: PHP code to create unique 3 digit combinations from array with following conditions
body: <p><strong>Conditions:</strong></p>
  
  <blockquote>
    <ol>
    <li>Starting digit should not be 0</li>
    <li>Succeeding digits should be greater than preceding numbers.</li>
    <li>The last digit can be 0</li>
    <li>The middle digit should not be 0</li>
    </ol>
  </blockquote>
  
  <p>We have succeeded in satisfying the first two conditions but because of the contradiction between second and third condition, I am not able to get the expected output.</p>
  
  <p>For example,
  The input 1234 gives output:</p>
  
  <pre><code>123
  124
  134
  234 
  </code></pre>
  
  <p>For the digits <code>12340</code>, the output should be:</p>
  
  <pre><code>123
  124
  134
  234
  120
  120
  140
  230
  240
  340
  </code></pre>
  
  <p>But it isn't working with what I have done.</p>
  
  <p>The code:</p>
  
  <pre><code>&lt;?
  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;
  }
  
  // example
  $chars = array('1', '2', '3','4','0');
  $output = pc_permute($chars);
  $a=count($output);
  for ($i = 0; $i&lt;count($output);$i++) {
    for ($j = 0; $j &lt; 3;$j++){
     $c[$i] = $c[$i].$output[$i][$j];
   }
  }
  $arr = array_unique($c);
  $last = end(array_keys($arr));
  $n=0;
  for($i = 0;$i &lt;= $last;$i++) {
    if(!empty($arr[$i])){
    $temp = $arr[$i];
    $d = str_split($temp);
    $e = end(array_keys($d));
    $flag = 0;
    for($j = 0;$j &lt; (count($d)-1); $j++) {
    if(($d[$j] &lt; $d[$j+1] &amp;&amp; $d[0] != 0)) {
     $flag = 1; 
    }
    else {
     $flag = 0;
     break;
    } 
   }
   if($flag == 1) {
     echo $temp;
     echo "&lt;br&gt;";
     $n++;
    }
  
   }
  }
  ?&gt;
  </code></pre>