3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** 初始化设置查询关键词和查询内容 **/ $names = array( '真三国无双', '无双剑姬', '虚无', '一时无两', '南无阿弥陀佛', '崖山之后无中国', ); $search = array("无","双"); /** 劈开字符串 **/ $res = array(); foreach($names as $name) { preg_match_all("/./u", $name, $match); $res[$name]['single'] = $match[0]; } print_r($res); /** 对字符串进行遍历,存储匹配到的位置,对没有匹配到所有的关键词的字符串剔除,匹配到所有的将位置相加,越小的排名越靠前 **/ foreach($res as $name => $v) { $pos = array(); foreach($v['single'] as $k => $s) { if(in_array($s, $search)) $pos[$s][] = $k; } if(count($pos) != count($search)) { unset($res[$name]); } else { $seq = 0; array_walk_recursive($pos, function($i) use(&$seq) { $seq += $i; }); $res[$name] = $seq; } } ksort($res); $res = array_keys($res); var_dump($res);
based on K0X7m
Output for 5.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Array ( [真三国无双] => Array ( [single] => Array ( [0] => 真 [1] => 三 [2] => 国 [3] => 无 [4] => 双 ) ) [无双剑姬] => Array ( [single] => Array ( [0] => 无 [1] => 双 [2] => 剑 [3] => 姬 ) ) [虚无] => Array ( [single] => Array ( [0] => 虚 [1] => 无 ) ) [一时无两] => Array ( [single] => Array ( [0] => 一 [1] => 时 [2] => 无 [3] => 两 ) ) [南无阿弥陀佛] => Array ( [single] => Array ( [0] => 南 [1] => 无 [2] => 阿 [3] => 弥 [4] => 陀 [5] => 佛 ) ) [崖山之后无中国] => Array ( [single] => Array ( [0] => 崖 [1] => 山 [2] => 之 [3] => 后 [4] => 无 [5] => 中 [6] => 国 ) ) ) array(2) { [0]=> string(12) "无双剑姬" [1]=> string(15) "真三国无双" }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/2WmVA on line 31
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/2WmVA on line 31
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/2WmVA on line 31
Process exited with code 255.