Skip to content
Advertisement

Referencing the id value from array and placing in a variable

I’m using CodeIgniter and I have a value that is being passed in my URL when I visit a page. The value that is passed is a string value, and there is an id that corresponds to that string in my database. Now I have a query in my model class that computes the string and returns it’s respective id. This id I want to use for filtering my table.

View Class:

<?php  
$sessn=$this->session->userdata(); 
$status = $this->input->get('status');
$source = $this->input->get('source');
$content['getsource'] = $this->leads_model->get_selected_source($source)->result_array();
  $get_src = $content['getsource'];
  print_r($get_src);
$post = array('fstatus'=> $status,'fsource'=> $get_src);
$postd = json_encode(array_filter($post));
?>

Now here print_r($get_src) gives Array ( [0] => Array ( [id] => 90 ) ). Now I want to place this id field inside my 'fsource'=> $get_src.

I’ve tried doing 'fsource'=> $get_src['id'] but this didn’t work.

Advertisement

Answer

You have 0 as a key in array so try like:

'fsource'=> $get_src[0]['id']
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement