php - How to get the key value from an array if given string value as a variable in Codeigniter -


i not sure if make sense in asking have model:

function update_profile_image($id, $image, $data){     $data1=array('profile_thumb'=> $data['images_urls'][$index]);     $this->db->where('property_ref_id',$id);     $this->db->update('vbc_property_images',$data1); } 

here $data array:

array ( [images_urls] => array     (         [0] => property_image_11.png         [1] => property_image_13.png         [2] => property_image_14.png     )  ) 

and $image in model name of image in array, e.g. 'property_image_13.png'.

i trying can key value $index([0], [1]..) $image in query automatically detect image selected.

please help.

you can loop on array key of image

foreach($data['images_urls'] $key => $value) {    if($value == $image) {        $index = $key;        break;    } } 

alternative solution use array_search()

$index = array_search($image, $data['images_urls']); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -