Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查是否可以使用PHP从随机字母字符串创建单词_Php_Arrays_String_Word_Letter - Fatal编程技术网

检查是否可以使用PHP从随机字母字符串创建单词

检查是否可以使用PHP从随机字母字符串创建单词,php,arrays,string,word,letter,Php,Arrays,String,Word,Letter,也请检查字母的重复。也就是说,beep。因为字符串包含两个e。但是egg是不可能的,因为只有一个g这应该可以做到: car is possible. egg is not possible. total is not possible. 这应该可以做到: car is possible. egg is not possible. total is not possible. 在验证字符串上使用字符后,该字符是否会下降?e、 g我们搜索car,验证字符串是“thecar”(car找到,验证字

也请检查字母的重复。也就是说,
beep
。因为字符串包含两个
e
。但是
egg
是不可能的,因为只有一个
g

这应该可以做到:

car is possible.
egg is not possible.
total is not possible.

这应该可以做到:

car is possible.
egg is not possible.
total is not possible.


在验证字符串上使用字符后,该字符是否会下降?e、 g我们搜索car,验证字符串是“thecar”(car找到,验证字符串现在是)->“the”?否。可以重复使用。字符在验证字符串上使用后是否会下降?e、 我们搜索汽车,验证字符串是“thecar”(汽车被找到,验证字符串现在是)->“the”?编号。可以重复使用。完美。谢谢最后3行应该在$arraylist.Perfect的foreach循环中。谢谢最后3行应该在$arraylist的foreach循环中。我有“鸡蛋是可能的”。但由于我的需要,“鸡蛋”这个词不可能出现。当我尝试这个的时候。我有“鸡蛋是可能的”。但由于我的需要,“鸡蛋”这个词不可能出现。
<?php
        $randomstring = 'raabccdegep';
        $arraylist = array("car", "egg", "total");

        foreach($arraylist as $word){
            $checkstring = $randomstring;
            $beMade = true;
            for( $i = 0; $i < strlen($word); $i++ ) {
                $char = substr( $word, $i, 1 );
                $pos = strpos($checkstring, $char);
                if($pos === false){
                    $beMade = false;
                } else {
                    substr_replace($checkstring, '', $i, 1);    
                }
            }
            if ($beMade){
                echo $word . " is possible \n";
            } else {
                echo $word . " is not possible \n";
            }
        }
    ?>
function find_in( $haystack, $item ) {
    $match = '';
    foreach( str_split( $item ) as $char ) {
        if ( strpos( $haystack, $char ) !== false ) {
            $haystack = substr_replace( $haystack, '', strpos( $haystack, $char ), 1 );
            $match .= $char;
        }
    }
    return $match === $item;
}

$randomstring = 'raabccdegep';
$arraylist = array( "beep", "car", "egg", "total");

foreach ( $arraylist as $item ) {
    echo find_in( $randomstring, $item ) ? " $item found in $randomstring." : " $item not found in $randomstring.";
}