我有一个数组保存这些数据的:如何在PHP中创建一个包含给定数组键的字符串?
Array (
[1402377] => 7
[1562441] => 7
[1639491] => 9
[1256074] => 10
)
如何可以创建一个包含上述阵列的钥匙串? 从本质上讲,我需要创建一个逗号分隔的字符串组成的数组的键
字符串看起来像:“键”,“钥匙”,“关键”
我需要创建一个新的数组由现有数组中的键组成?
我需要这样做的原因是因为我将使用WHERE in()
语句来查询MySQL数据库。我宁愿不必使用foreach语句来查询数据库。我正确地处理这个问题吗?
我试过使用while
语句,我可以打印我需要的数组键,但我需要这些键才能发送到我的模型。
,让我打印数组键的代码看起来是这样的:
while($element = current($array)) {
$x = key($array)."\n";
echo $x;
next($array);
}
请注意[注入](http://unixwiz.net/techtips/sql-injection.html)漏洞。熟悉[数组函数](http://it.php.net/manual/en/ref.array.php)。 – outis 2012-01-13 07:28:56
[PHP将数组拆分为两个数组 - 键数组和值数组](http://stackoverflow.com/questions/6234696/),[MySQL Prepared statement with a variable size variable list](http:// stackoverflow.com/questions/327274/)。 – outis 2012-01-13 08:01:03
... [有一种方法来获取数组的所有键?](http://stackoverflow.com/questions/3407967/),[打印数组的键](http://stackoverflow.com/ (参考SQL IN子句?)(http://stackoverflow.com/questions/337704/),[PreparedStatement IN子句的替代?](http:// stackoverflow。COM /问题/ 178479/PreparedStatement的,在子句的替代品) – outis 2012-01-13 08:17:43