Question: I am not sure if I would make any sense in asking this but I have a 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 is an array:

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

)

```

And $image in model is the name of any image in this array, e.g. 'property\_image\_13.png'.

I am trying to do something where I can get key value like $index([0], [1]..) by $image so that in my query it will automatically detect which image was selected.

Please help.

Answer: 
You can loop on the array to get the key of the image

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

```

Alternative solution is to use `array_search()`

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

```
If I understand your question correctly, you want to search `$data` for the value defined in `$image`, and return the key of the matching element. If so, [array\_search](http://php.net/manual/en/function.array-search.php) is what you need.

`$key = array_search($image, $data);`

Description from manpage:

> 
> Searches the array for a given value and returns the corresponding key if successful
> 
> 
>