codeigniter get lst inserted id

PHP
$id = $this->db->insert_id();function add_post($post_data){
   $this->db->insert('posts', $post_data);
   $insert_id = $this->db->insert_id();

   return  $insert_id;
}
Source

Also in PHP: