Home > Backend Development > PHP Tutorial > PHP搜索 $keyword结果与此同时等于另一个结果

PHP搜索 $keyword结果与此同时等于另一个结果

PHP中文网
Release: 2016-06-13 12:06:49
Original
1188 people have browsed it

  PHP搜索 $keyword结果同时等于另一个结果
PHP+mysql 例如我想搜索关键词 $keyword为25*50的结果中同时显示25*50及50*25的结果,然后继续搜索25*50*2.5的结果中也同时显示50*25*2.5的结果。(后面还有25*50*1.1到25*50*4.75)
需要PHP进行怎样的判断或者方法。
------解决思路----------------------
你可能要的是这个

$key = '20*50*30';
$arr = explode('*', $key);
print_r(Arrangement($arr));

//排列 Arrangement
function Arrangement($arr = array(), $res = '') {
  if(! is_array($arr) ) $arr = str_split($arr);
  if(empty($arr)) $array[] = $res;
  else foreach($arr AS $k => $v) {
    unset($arr[$k]);
    foreach( Arrangement($arr, trim("$res*$v", '*')) AS $t) $array[] = $t;
    $arr[$k]    = $v;
  }
  return  $array;
}
Copy after login
Array
(
    [0] => 20*50*30
    [1] => 20*30*50
    [2] => 50*30*20
    [3] => 50*20*30
    [4] => 30*20*50
    [5] => 30*50*20
)
Copy after login

 以上就是PHP搜索 $keyword结果与此同时等于另一个结果的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template