title: how to concatenate the array elements and store them in a field in codeigniter php
body: <p>i am using PHP Codeigniter for a project i need to concatenate  multiple fields and make a new field called key which should be stored in same table. For eg if i insert name:jack country:USA code:+691 then my code should dynamically store JACK-USA-691 into the key field of my table. I have a base model which performs my CRUD operations. below is my controller code to get a new user(reseller) and also the model from where i get a new user(reseller):</p>
  
  <p>Controller:</p>
  
  <pre><code>public function edit ($id = NULL)
  {
      // Fetch a user or set a new one
      if ($id) {
          $this-&gt;data['user'] = $this-&gt;reseller_m-&gt;get($id);
          count($this-&gt;data['user']) || $this-&gt;data['errors'][] = 'User could not be found';
      }
      else {
          $this-&gt;data['user'] = $this-&gt;reseller_m-&gt;get_new();
      }
  
      // Set up the form
      $rules = $this-&gt;reseller_m-&gt;rules_admin;
      $id || $rules['password']['rules'] .= '|required';
      $this-&gt;form_validation-&gt;set_rules($rules);
  
      // Process the form
      if ($this-&gt;form_validation-&gt;run() == TRUE) {
  
  
  
  $data = $this-&gt;reseller_m-&gt;array_from_post(array('sip_username','sip_password','key','allocation_block','name','email','password','phone','balance','user_num','address','country','created','modified','status'));
  
  
          $data['password'] = $this-&gt;reseller_m-&gt;hash($data['password']);
  
          $values=array($this-&gt;input-&gt;post('name'),$this-&gt;input-&gt;post('country'),$this-&gt;input-&gt;post('name'));
  
          $key=implode('-',$values);
  
          $this-&gt;db-&gt;insert('reseller',$key);
  
  
  
          $key=$this-&gt;reseller_m-&gt;save($data, $id);
  
          for($i=1; $i&lt;=$data['user_num'];$i++)
              {
              $userdata=array('key'=&gt;$key);
          // here users is taken name of user table with retailer_id is field
              $this-&gt;user_m-&gt;save($userdata,$id);
               }
  
  
  
          redirect('admin/reseller');
      }
  
      // Load the view
      $this-&gt;data['subview'] = 'admin/reseller/edit';
      $this-&gt;load-&gt;view('admin/_layout_main', $this-&gt;data);
  }
  </code></pre>
  
  <p>the model:</p>
  
  <pre><code>public function get_new(){
      $user = new stdClass();
  
  //          $user-&gt;id = '';
      $user-&gt;sip_username='';
      $user-&gt;sip_password='';
      $user-&gt;key='';
      $user-&gt;allocation_block='';
      $user-&gt;name='';
      $user-&gt;email = '';      
      $user-&gt;password = '';
      $user-&gt;phone=''; 
      $user-&gt;user_num=''; 
      $user-&gt;address = '';
      $user-&gt;status = '';
      $user-&gt;country=''; 
      $user-&gt;created = '';
      $user-&gt;modified  = '';
      $user-&gt;balance = '';
      return $user;
      $this-&gt;session-&gt;set_userdata($data);
  
  }
  </code></pre>
  
  <p>One solution that i thing is create a user the get its id and update it by concatenating the fields. i also find it right but how to concatenate elements of array ? and how to do this dynamically? Please help me with my code! Can i store the concatenated string in my database dynamically?</p>