php - How to use function in_array with CodeIgneter -


i trying use php function in_array within view using codeigneter.

this method

class user_details extends ci_model {  public function checkid(){ $query = $this->db->query("select id users");  return $query->result_array(); 

}

this controller

$this->load->model('user_details');  $data['alluserid'] = $this->user_details->checkid(); $this->load->view('user_details/content',$data); 

this script trying use in view

$id = $this->uri->segment(4);//user's id example: 218   if(in_array($id,$alluserid)){ echo 'exists'; } else { echo 'does not exist'; } 

unfortunately script not work expected.

if check array using print_r($alluserid) following result:

array ( [0] => array ( [id] => 217 ) [1] => array ( [id] => 218 ... ...and on... 

last week started learning codeigneter , did not understand approach yet.

in_array() accept single dimensional array , passing 2 dimensional array. try converting single dimensional array like

$array = array_map('current', $alluserid);  if(in_array($id, $array)){  echo 'exists'; } else {   echo 'does not exist'; } 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -