【发布时间】:2012-03-09 20:04:29
【问题描述】:
我的函数接收一个数组作为参数:
array(6) {
[0]=>
string(7) "usuario"
[1]=>
string(4) "john"
[2]=>
string(5) "senha"
[3]=>
string(40) "7c4a8d09ca3762af61e59520943dc26494f8941b"
[4]=>
string(9) "pessoa_id"
[5]=>
string(1) "2"
}
我需要什么:
SELECT * FROM (`funcionarios`) WHERE `usuario` = 'john' AND `senha` = '7c4a8d09ca3762af61e59520943dc26494f8941b' AND `pessoa_id` = '2'
我需要用它创建一个 WHERE,我正在使用 CodeIgniter,我找到了这个愚蠢但有效的解决方案:
foreach($params as $x) {
if($pos%2==0)
$chave = $x;
else
$valor = $x;
$pos++;
if($pos%2==0)
$this->db->where($chave, $valor);
}
我正在尝试寻找对用户更友好的东西,因为会有其他人使用此代码。
最好的方法是什么?
【问题讨论】:
-
如果你对传入的数组有任何控制权,请帮自己一个忙,把它变成一个关联数组。
标签: php arrays codeigniter