my code stock.com

Distributions in rows and columns dates arrays

Snippet options

Download: Download snippet as distribution.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

class Distribution{

function eliminaVcad($vn,$idy){
      $l=false;$r=false;
      $cad=explode(',',$vn);
      foreach($cad as $n=>$v){
       if ($v==$idy){  // $idy  es valor o codigo que se esta quitando de la cadena del $v
           if (@$cad[$n-1]!=""){
               $l=true;
           }

           if (@$cad[$n+1]!=""){
               $r=true;
           }
       }
      }

      if (($l&&$r)||$l){
        $idy=str_replace(",$idy","",$vn);
      }elseif ($r){
        $idy=str_replace("$idy,","",$vn);
      }else{
        $idy=str_replace("$idy","",$vn);
      }
      return $idy;
    }

    function borraIgual($v) {
     $zc=count($v);
     foreach ($v as $key => $value) {
       $x = explode(",",$value);
       $nue = count($x);
       if ($nue>1) {
           $x1 = array_slice($x,1);
           for ($i=$key+1;$i<$zc;$i++) {
              $x2 = explode(",",$v[$i]);
              $nue1 = count($x2);
              if ($nue1>1) {
                  $x3 = array_slice($x2,1);
                  if ((in_array($x[0],$x3))&&(in_array($x2[0],$x1))) {
                     $v[$i]= eliminaVcad($v[$i],$x3[array_search($x[0],$x3)]);
                  }
              }
           }
       }
     }
     return $v;
    }

    function distribuye($vu){
      $ban = true;
      $ni=0;
      while ($ban) {
        $num1=0;
        foreach ($vu as $key => $value) {
          $nreg = count(explode(",",$value));
          if ($nreg>1){
              $num1++;
          }
        }
        if ($num1==0){
            $ban=false;
        }
        if ($ban){
            foreach ($vu as $key => $value) {
              $vc = explode(",",$value);
              $nl = count($vc);
              if ($nl>1){
               if ($key==0){
                  $vf[$ni]=$vc[0].",".$vc[1];
                  $vu[$key]=eliminaVcad($vu[$key],$vc[1]);
               }else{
                 if ($vf[$ni]!=""){
                  $vc1 = explode(",",$vf[$ni]);
                  $nvu = count($vc1);
                  $nel = 0;
                  $vl="";
                  foreach ($vc as $key1 => $value1) {
                    if((in_array($value1,$vc1))&&($key1==0)){
                        break;
                    }
                    if(!in_array($value1,$vc1)){
                        $nel++;
                    }
                    if ($nvu==$nel){
                        $vl=$value1;
                        break;
                    }
                  }

                  if ($nvu==$nel){
                   $vf[$ni].=",".$vc[0].",".$vl;
                   $vu[$key]=eliminaVcad($vu[$key],$vl);
                  }
                 }else{
                   $vf[$ni]=$vc[0].",".$vc[1];
                   $vu[$key]=eliminaVcad($vu[$key],$vc[1]);
                 }
               }
              }
            }
            $ni++;
        }
      }
      return $vf;
    }
    }

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.