php二维数组置换…;单个语音有多个英文字母

问题描述 投票:0回答:1

我有一组具有多个备用英文字母的拼音

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

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

--

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

我有包含单词的单词表切放标签

我想在2d数组上置换并生成具有所有可能单词的查询,

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

或者我们也可以包括并继续上面的程序逻辑要求系列

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

我需要的是像$ word {$ i]这样的数组变量,具有上面所有可能的排列词。当我在查询可能的单词之上运行时,它将仅在表中找到“ cut”,而我将“ cut”替换为“ ڪَٽ”。我仍然尝试过的编程是

<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>

//我在上面制作了三个名为list0,list1,list3的列表框线list0 =“ c,q,k”list1 =“ u,a”list2 =“ t”

 <?php
            //echo "($i-i)--  ($x-X) <BR>";
            echo $q[$i][$x]."<BR>";
        }
    }
php combinations permutation
1个回答
0
投票

这是我尝试过的完整程序。...事情是“如果有人用英语将“ fahad”字符串写成英语,那么我不得不将其翻译成sindhi,在sindhi语言中,单个英文字母的多个替代项,例如f有2个替代项,a有trhee替代项َ,ا和h具有三个候补å,ح,ھ和d具有三个候补د,ڊ,所有替代者都根据英语字母写到数据库表中。......首先,我将每个字母搜索到字母替代表中.....如果发现,我将一个一个地放到列表/选择框中....所有列表框都是等于“ fahad”的长度数,因此将生成5个列表框。并将当前列表框的长度放入$ _POST ['leng']文本框.....现在我在此permutation of multidimensional array]上对$ q数组进行排列

然后在我计算出每个5个字的长度之后

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>++++++";



}
© www.soinside.com 2019 - 2024. All rights reserved.