我有一个 PHP 数组
$array = array(
"PHP server side scripting",
"CSE for designing",
"Client side scripting JavaScript, HTML etc",
"Java object oriented programming"
}
和一个数据库表
+-------+-----------------+
| id | language |
+-------+-----------------+
| 1 | PHP |
| 2 | JavaScript |
| 3 | CSE |
| 4 | C++ |
+-------+-----------------+
如何使用查询将数组项与数据库表的字段部分匹配。
必需的输出仅与 PHP 数组匹配的语言
+-------+-----------------+
| id | language |
+-------+-----------------+
| 1 | PHP |
| 2 | JavaScript |
| 3 | CSE |
+-------+-----------------+
我尝试了以下但没有得到实际结果。
foreach($array as $val) {
$sql = "SELECT * FROM my_table WHERE language LIKE '%$val%'";
//remaining code
}
提前致谢。