我有两张表,一张是文本字符串,一张是单词。

php - 比较两个sql表-LMLPHP

我如何获取表 A 中的每个字符串/行,并查看表 A 中每个字符串包含多少个来自表 B 的“单词” - 并获得如下结果:

表A
id: 1 包含表 B 中的 2 个单词(car、red)
id: 2 包含表 B 中的 2 个单词(house、hill)
id: 3 包含来自表 B 的 0 个单词
id: 4 包含来自 TABLE B 的 2 个单词(small、shoe)

最佳答案

<?php
// Get $TableA from TableA and $TableB from Table B (std code)

$result = array();
foreach ($TableA as $id => $string) {
    $result[$id] = array();
    $words = explode(' ', $string);
    foreach ($words as $word) {
        if (in_array($word, $TableB)) {
            $result[$id][] = $word;
        }
    }
}

// - display $result - left as exercise!

关于php - 比较两个sql表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46258465/

10-10 00:24
查看更多