duanna2026 2016-04-19 16:14
浏览 24

php for循环并保持历史记录生成一个包含所有值的新数组

$Xn = count($where = array(1, 2, 3, 4, 5, ... , $n))/3;

where $n is multiple of 3 objects!!!

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];
}

all i want is to create a big array with all values inside! like this:

array($field[0], $operator[0], $value[0], $field[1], $operator[1], $value[1], $field[2], $operator[2], $value[2]...)

or 3 small arrays like this:

$field_$n = array($field[0], $field[1], $field[2]...)

etc.. how can this be done? thanks in advance!!!

  • 写回答

1条回答 默认 最新

  • dongtang1997 2016-04-21 08:03
    关注

    sorry guys for bad language and meaning in the question!!, what i had in mind was this!!

    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;
    }
    

    and so to get the values from my table i used this:

    public function get_X_single($table, $where) {
        return $this->action_X_single('SELECT *', $table, $where);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错