I am using codeigniter and doing some insert and update operation on my table from the associative array (which comes from the external website) , where the number of fields are not always same.
Here is my code.
$url ="http://api.peerindex.net/1/profile/show.json?id=$twittername&api_key=xxxxxx";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$peerdata = curl_exec($ch);
curl_close($ch);
if (strlen($peerdata)>10)
{
$peerdata = json_decode($peerdata);
$this->db->where ("userid", $this->userinfo->userid);
$this->db->update('userpeerdata', $peerdata);
}
My Table userpeerdata contains around 6 columns but some columns are not exist. What I want is it should take only those columns which are present in database, other should ignore. How can I do this in simple.

You should use Codeigniter’s array helper. They have a nice little function called
elements(), which will extract only the elements you want: