$Xn = count($where = array(1, 2, 3, 4, 5, ... , $n))/3;
其中$n是 3 个对象的倍数!!
for($i = 1; $i <= ($Xn); $i++) {
$field[$Xn-$i] = $where[(3*$i)-3];
$operator[$Xn-$i] = $where[(3*$i)-2];
$value[$Xn-$i] = $where[(3*$i)-1];
}
我想要的只是创建一个包含所有值的大数组! 像这样:
array($field[0], $operator[0], $value[0], $field[1], $operator[1], $value[1], $field[2], $operator[2], $value[2]...)
或 3 个小数组,如下所示:
$field_$n = array($field[0], $field[1], $field[2]...)
等。。怎么能做到这一点?提前谢谢!!
对不起,伙计们在问题中的语言和含义不好!,我想到的是这个!!
public function action_X_single($action, $table, $where = array()) {
$Xn = count($where)/3;
$operators = array('=', '>', '<', '>=', '<=');
for($i=1; $i<=$Xn; $i++){
$field[] = array( 'field' => $where[(3*$i)-3] );
$operator[] = array( 'operator' => $where[(3*$i)-2] );
$value[] = array( 'value' => $where[(3*$i)-1] );
}
$sql .= "{$action} FROM {$table} WHERE " ;
for($i=0;$i<$Xn;$i++)
{
if(($i)==0)
{
$sql .= implode(' ', $field[0]) . " " . implode(' ', $operator[0])." ?";
}
else
{
$sql .= " AND ".implode(' ', $field[$i]) . " " . implode(' ', $operator[$i])." ?";
}
}
for($i=0;$i<$Xn;$i++) {
if($i==0) {
$values .= implode(' ', $value[0]);
}else {
$values .= " ".implode(' ', $value[$i]);
}
}
if(!$this->query($sql, explode(' ', $values))->error()) {
return $this;
}
return false;
}
因此,为了从我的表中获取值,我使用了这个:
public function get_X_single($table, $where) {
return $this->action_X_single('SELECT *', $table, $where);
}