1

so I ended up with this project, that,due to my opinion, is some levels greater than my skills, so I would like you to help me.

This project's functionality is to write some words in those 4 columns,which have to be combined.The words that are in the same column mustn't be combined. You can only combine words with the rest of the columns.

I will give you the full code so you can see what I have done.

The second question I have is how you delete a special character(in this case, the "\n")

    <?php
    if(isset($_POST['submit']))
    { 
     if(isset($_POST["separator"])){$separator= $_POST["separator"];}
     if(isset($_POST["match"])){$matchType = $_POST["match"];$matchArr = array();
     foreach($matchType as $match)
     {
      $matchArr = $match;
     }}
     $j=0;
     $columnCount=array();
     $wordArr[] = array();
     $wordArrRows[] = array();
     $protasi="";
     $wordsCombinations = 1;
     $wordsCounter = 0;
     for($i=0; $i<4; $i++)
     { $words=0;
      $enterChar=0;
      if(isset($_POST["in$i"]) && !empty($_POST["in$i"]))
      {
       $input=$_POST["in$i"];
       $enterChar = substr_count($input,"\n");
       $words= $enterChar+1;
       if($words>0)
       {
        $wordArr[$j]= explode("\n",$input);
        $wordArrRows[$j]= $words;
        $j++; 
       }
       $wordsCombinations*=$words; 
      }  
     }
     
     $i2=0;
     $columnCounter = array_fill(0, $j, "0");
     while($wordsCounter < $wordsCombinations)
     {
      if($i2<sizeof($columnCounter) && $columnCounter[$i2] < $wordArrRows[$i2])
      {
       echo "grammi: ".$i2." <br>";
       $i=0;
       for($i=0; $i<$j; $i++) 
       {    
        //echo "wordArr[".$i."][".$columnCounter[$i]."]".$separator;
        echo $wordArr[$i][$columnCounter[$i]]."  ";    
       }
       $columnCounter[$i2]++; 
       if($columnCounter[$i2] >= $wordArrRows[$i2] ){$columnCounter[$i2]=0;}
       echo "<br>";  
      }
      $i2++;
      if($i2>=sizeof($columnCounter)){$i2=0;}   
      $wordsCounter++;
     }
     

     
    }
     ?>

(NOTE: don't use the radio buttons or the check boxes, they're not functional).

enter image description here

  • 1
    You should make an effort to provide a minimal example that outlines your problem. – apokryfos Sep 13 '16 at 13:53
  • I have an array with X lines and every line has different column number/size. I want I combine every word with the words of the other columns of the rest of the lines, but not the words of the same line. In this code, I create a matrix with all those words and I'm trying to full combine them.But there's a mistake and they don't fully combine with each other – Tinakicious Sep 13 '16 at 14:07
  • I added an image to show you what i mean. – Tinakicious Sep 13 '16 at 14:14
  • What you need is called a cross product. Check http://stackoverflow.com/questions/6311779/finding-cartesian-product-with-php-associative-arrays – apokryfos Sep 13 '16 at 14:34
  • oh thank you very very much! – Tinakicious Sep 22 '16 at 07:53
  • Any idea on keeping textfield values in their textfields after submit? – Tinakicious Sep 22 '16 at 07:54

1 Answers1

0

EDIT What is the expected result for that example? The second question: trim() to delete "\n"

Chart
  • 32
  • 4