php two dimensional array permutation...; single phonics have multiple letters in english

i have array of phonics having multiple alternate English letters

$q[0][0]="c";
$q[1][0]="k";
$q[2][0]="q";

---
$q[0][1]="u";
$q[1][1]="a";

--

$q[0][2]="t"

i have table of words which contain words cut put tag

i want to permute above 2d array and generate query having all possible words as

cut
qat
kut
--
cat
qut
kat
----

or we may include also and continue above series for programmatic logic requirements

tac
tuc
tak
---
tuq
taq
tuk
---
act
ukt
uct
---

all i need is array variable like $word{$i] having all above possible permutations words. when i would run above query possible word, it will only find "cut" in table and i would replace "ڪَٽ" with "cut".... yes its roman translitration the programming still yet i have tried is

<input type="text" name="leng" id="leng" value="" ><input type='submit' name='submit'></form>
<?php 
if(isset($_POST['submit'])){

    for($i=0; $i<=3; $i++){ //3 is number of listboxes or length of given string

        //echo $list[$i]; 

        for ($x=0; $x<= $_POST['leng']; $x++){
?>
<script>
document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;
 </script>

// i have made three list boxes named list0, list1, list3 in above line list0="c, q, k" list1="u, a" list2="t"

 <?php
            //echo "($i-i)--  ($x-X) <BR>";
            echo $q[$i][$x]."<BR>";
        }
    }

1 answer

  • answered 2019-12-10 17:58 sindhuazahar

    here is the complete program i have tried.... the thing is "if some one write "fahad" string into English, then i have had to translitrate it into sindhi and in sindhi language there are multiple alternates of single english letter like f has 2alternates, a has trhee alternates َ، آ، ا and h has three alternates ه، ح، ھ and d has three alternates د، ڊ، ڏ all alternates are written into database table against english aletter....... first i search each letter into letter alternate table..... if found i put one by one to list/select boxes.... all listboxes are equal to length number of "fahad" so 5 listboxes are generated..... and put current listbox's length into $_POST['leng'] textbox..... now i do permutation of $q array on this permutation of multidimensional array

    then after i calculate each 5 word length

    global $servername;
        global $username;
        global $password;
        global $dbname;
    
    
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "tsrs";
    //////////////////////
    
    global $q;
    $q=array();
    
    //////////////////////
    for ($n=0; $n<=strlen("fahad"); $n++){
    
    $i=substr("fahad", $n, 1);
    //echo $i;
    
    /////////////////////
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
       die("Connection failed: " . $conn->connect_error);
    } 
    mysqli_set_charset($conn,"utf8");
    $sql = "SELECT * FROM duplicate WHERE engletter='$i' order by id";
    $result = $conn->query($sql);
    global $m;
    $m=0;
    
    if ($result->num_rows > 0) {
    $altrntcount=$result->num_rows; 
    
    
        while($row = $result->fetch_assoc()) {
        $q[$n][$m]=$row['sinletter']    ;
        echo $q[$n][$m]."<BR>";
    
        $m=$m+1;
        }
        }
    
    }
    echo "<form method='post'>";
    
    for ($n=0; $n<=strlen("fahad")-1; $n++){
    $list[$n]="list".$n;
    echo $list[$n];
    echo "
    <select name=\"".$list[$n]."\" id=\"".$list[$n]."\">";
    
    for ($m=0; $m<=$altrntcount-1; $m++){
    if ($q[$n][$m]<>""){
    echo "<option value=\"".$q[$n][$m]."\">".$q[$n][$m]."</option>";
    
    }
    
    }
    echo "</select>";  
    }?> 
    <input type="text" name="leng" id="leng" value="1" ><input type='submit' name='submit'></form>
    <?php 
    if(isset($_POST['submit'])){
    
    for($i=0; $i<=strlen("fahad")-1; $i++){
    
        //echo $list[$i]; 
    
    
    
    
    
    for ($x=0; $x<= $_POST['leng']+1; $x++){
    
        ?>
    
        <script>
    
    
    
        document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;
    
     </script>
     <?php
    
        echo $i."-i: I : ".$x.": X <BR>";
    
        echo $q[$i][$x];
    
    }
    
    }
    echo "<h1>".($_POST['leng'])."zzz</h1>";
    
    
    
    
    
    
    
    echo "-----<BR><BR><BR>++++++";
    
    
    
    }
        ?>
    
    <?php
    global $q;
    
    
    //$arrStart = array(
     //array('ف', 'ڦ', 'په'),
       // array('ح', 'ه'),
        //array('د', 'ڊ','ڏ')
    //);
    
    //$arrStart= $q[$i][$x];
    $arrPositions =     ();
    $arrResult = array();
    
    //get a starting position set for each sub array
    for ($i = 0; $i < count($q); $i++)
        $arrPositions[] = 0;
    
    //repeat until we've run out of items in $q[0]
    while (array_key_exists($arrPositions[0], $q[0])) {
        $arrTemp = array();
        $blSuccess = true;
    
        //go through each of the first array levels
        for ($i = 0; $i < count($q); $i++) {
            //is there a item in the position we want in the current array?
            if (array_key_exists($arrPositions[$i], $q[$i])) {
                //add that item to our temp array
                $arrTemp[] = $q[$i][$arrPositions[$i]];
            } else {
                //reset this position, and raise the one to the left
                $arrPositions[$i] = 0;
                $arrPositions[$i - 1]++;
                $blSuccess = false;
            }
        }
    
        //this one failed due to there not being an item where we wanted, skip to next go
        if (!$blSuccess) continue;
    
        //successfully adding nex line, increase the right hand count for the next one
        $arrPositions[count($q) - 1]++;
    
        //add our latest temp array to the result
        $arrResult[] = $arrTemp;
    
    }
    
    
    
        print_r($arrResult);
    
    
    
    
    
        if(isset($_POST['submit'])){
    
    for($i=0; $i<=count($arrResult)-1; $i++){
    
        //echo $list[$i]; 
    
    
    ?>
    
        <script>
    
    
    
        document.getElementById("leng").value = document.getElementById("<?php echo $list[$i]; ?>").length;
    
     </script>
     <?php  
    
    for ($x=0; $x<= $_POST['leng']+2; $x++){
    
    
    
    
    
    
        //echo $i."-i: I : ".$x.": X <BR><BR><BR>";
    
        echo $arrResult[$i][$x];
    
    }
    echo "<BR><BR>";
    }
    echo "<h1>".($_POST['leng'])."zzz</h1>";
    
    
    
    
    
    
    
    echo "-----<BR><BR><BR>++++++";
    
    
    
    }