Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中逃离整个阵列_Php_Arrays_Codeigniter - Fatal编程技术网

Php 在codeigniter中逃离整个阵列

Php 在codeigniter中逃离整个阵列,php,arrays,codeigniter,Php,Arrays,Codeigniter,我想用一个转义函数来转义整个数组到目前为止,我所做的是我可以通过post转义一个值,但是转义每个输入的过程非常耗时。我尝试创建一个函数来转义整个数组,因为我使用codeigniter,所以大部分工作都是用数组完成的 以下是控制器中的函数,以了解更多说明 $data=array( 'fname'=>$this->input->post('fname'), 'lname'=>$this->input->post('lname'),

我想用一个转义函数来转义整个数组到目前为止,我所做的是我可以通过post转义一个值,但是转义每个输入的过程非常耗时。我尝试创建一个函数来转义整个数组,因为我使用codeigniter,所以大部分工作都是用数组完成的

以下是控制器中的函数,以了解更多说明

$data=array(
      'fname'=>$this->input->post('fname'),
      'lname'=>$this->input->post('lname'),
      'username'=>$this->input->post('username'),
      'email'=>$this->input->post('email'),
      'birth_year'=>$this->input->post('birth_year'),
      'mobile_phone'=>$this->input->post('mobile_phone'),
      'bio_data'=>$this->input->post('bio_data'),
      'gender'=>$this->input->post('gender'),
      );
      $data1=$this->adminmodel->escape_array($data);
下面是转义单个post值的函数

function escape($input){
        if(!empty($input)){
            $input = mysql_real_escape_string($input);
        }
        return $input;
    }
这是一个转义整个数组的函数,但它不起作用,可能我做错了什么,任何帮助都会非常有用

function escape_array($array){
        if(!empty($array)){
         for($i=0; $i<sizeof($array); $i++)
         {  
            $array = mysql_real_escape_string($array[$i]);
         }
        }
        return $array;
    }
函数转义数组($array){
如果(!空($array)){

对于($i=0;$i您正在$array中分配转义字符串,而需要将其分配给和数组变量。下面是为您更新的代码:

function escape_array($array){
        $posts = array();
        if(!empty($array)){
         foreach($array as $key => $value)
         {  
            $posts[$key] = mysql_real_escape_string($value);
         }
        }
        return $posts;
    }

我更新了用于关联数组的代码。我假设您正在传递一维数组以转义数组函数。

您的意思是这样的?数组映射('mysql\u real\u escape\u string',$array);获取的错误或输出,请共享…..更改数据库驱动程序….
mysql.*
即将被删除。当我传递整个数组未定义的偏移量时,我收到此错误:0不,不需要额外的函数,只需使用活动记录。这应该会自动转义输入。我认为问题在于关联数组,因为循环可以工作,它根据数组长度表示未定义的偏移量0:1 2 3等等如果它的关联数组需要使用foreach而不是for循环,还需要将转义值分配给数组,并将索引作为关联数组的键。希望您能提供一些帮助