Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
要在sql数据库中查找的数组字符串,php_Php_Arrays - Fatal编程技术网

要在sql数据库中查找的数组字符串,php

要在sql数据库中查找的数组字符串,php,php,arrays,Php,Arrays,我尝试在sql数据库中查找字符串的方法。我想如果我有字符串“abcde”,为了得到准确的结果,我尝试“选择…从…中选择列='abcde'或列='abcdd'或列='abcd'或…”,我尝试找到获得内爆数组的方法,如下所示: [0]=>a b c d e, [1]=>a b c d, [2]=>a b c, ... [n]=>a Can i do 像那样 非常感谢。我不知道你为什么要这样做,但这可以做到: $string = "Hello everybody, ni

我尝试在sql数据库中查找字符串的方法。我想如果我有字符串“abcde”,为了得到准确的结果,我尝试“选择…从…中选择列='abcde'或列='abcdd'或列='abcd'或…”,我尝试找到获得内爆数组的方法,如下所示:

[0]=>a b c d e,
[1]=>a b c d,
[2]=>a b c,
...
[n]=>a
Can i do 
像那样


非常感谢。

我不知道你为什么要这样做,但这可以做到:

  $string = "Hello everybody, nice to meet you";
  $parts = explode(" ", $string);
  $new_array = Array();

  for($i = 0; $i < count($parts); $i++)
  {
      $new_array[$i] = '';
      for($j = 0; $j < count($parts) - $i; $j++)
      {
          $new_array[$i] = $new_array[$i]." ".$parts[$j];
      }
  }

  print_r($new_array);

您可以使用标记化字符串,构建数组,然后使用以下方法将其反转:

输出:

Array
(
    [0] => foo bar baz
    [1] => foo bar
    [2] => foo
)


看到结果了吗?

——您尝试了什么?对于sql数据库的搜索,我先分解字符串,然后再内爆,但如何才能得到这样的数组来将其内爆为sql查询。我想您必须自己构造数组。迭代需要多少数组,然后对字符串进行相应的内爆。我不知道搜索结果的准确度需要多少数组,我尝试了所有这样的数组(abcd)或(abc)或…为什么?你们确定你们不仅仅需要一系列的单词吗?你的阵列对我来说有点多余。。。[
你好
大家
很好
见面
谢谢你
]。我找到路了。
$string = 'foo bar baz';
$results = array(); $current = '';
foreach (preg_split('/ +/', $string) as $token) {
    $current = strlen($current) ? "$current $token" : $token;
    $results[] = $current;
}

print_r(array_reverse($results));
Array
(
    [0] => foo bar baz
    [1] => foo bar
    [2] => foo
)
<?php

   $string = "Hello everybody, nice to meet you";

   //remove the comma
   $string = str_replace(',', '', $string);

   //explode for each words with ' '(space) delimiter
   $path = explode(' ', $string);
   $final = array();

   array_push($final, implode(' ', $path));

   foreach($path as $el){
       //remove max array element
       $last_el = count($path) - 1;
       unset($path[$last_el]);

       //set the final array one by one.
       array_push($final, implode(' ', $path));
   }

   //Show the result.
   foreach($final as $row){
       echo $row . ' <br />';
   }

?>