简体   繁体   中英

Need to get keys form my array for a foreach loop for where in codeigniter

Im trying to make an search function in codeigniter. I have an array with the value of multiple diffrent checkboxes. (groups, times, special etc)

Im first using the keys form te array to make the search array like so

 $data = array_keys($data);
    $find =  array();
 foreach($data as $selection){
     if(!strpos($selection,'groep') == 0){

        $find[$selection] = 1 ;
     }

     $find[$selection] = 1 ;

 }

the result of the array is like this:

Array ( ["fri_morning"] => 1 ["groep_1"] => 1 )

what isnt working is the next bit of code where im trying to use the second array to make multiple where selections for my query

im doing it like this:

 $where = '';

    foreach($find as $finds){
        echo array_keys($finds);die();
        $name = key($finds);
       $where .=  '$this->db->where'.name.','.$finds[$name].')';
    };

Im getting the following error

Message: array_keys() expects parameter 1 to be array, integer given

What am i doing wrong/missing here

foreach($find as $finds => $value){
                    ^         ^
                   Key      Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM