Question: I have several **arrays of string** and given a specific **input key** string I'm trying to return the corresponding key.

For example if the input value is 'a1' it should return 'aa' because 'a1' is part of the array values of key 'aa'.

```
 inputKey = 'a1';
 dict = {
    'aa': ['a1', 'a2'],
    'bb' : ['b1', 'b4', 'b6']
    ...
  };

  /
  // _.contains())

```

I was thinking of looping over each element in the dictionary and if the value exists in the array then return the key.

Is this the best way to go about doing this? (finding the corresponding key for an array of values) in other words (mapping down some specific values to another value).

Answer: 
If you're using PHP5.6 or later, you could use [argument unpacking](http://php.net/manual/en/migration56.new-features.php) to deal with the bind\_param which is the hardest part of the problem. Try something like this:

```
$update_fields = json_decode($_POST['myform']['update_fields'], true);
$sql_fields = array();
$bindtypes = "";
$bindings = array();
foreach (array_column($update_fields, 'attr_name') as $field) {
    $sql_fields[] .= "`$field` = ?";
    $bindtypes .= "s";
    $bindings[] = $_POST['myform'][$field];
}
$sql = "UPDATE `table_name` SET " . implode(',', $sql_fields) . " WHERE `id` = ?";
$bindtypes .= "i";
array_unshift($bindings, $bindtypes);
$bindings[] = $_POST['myform']['id'];
$query = $db->prepare($sql);
$query->bind_param(...$bindings);
$query->execute();

```
Run Foreach on fields and concat each field with incremented number, and concat these

```
$i=1;$par='';
Foreach($fields as $k=>$v)
{
$par.="$k=:param$i";
    $i++;
}

```

Concat this into query string. Then loop through fields again calling bind param

```
$i=1;$par='';
Foreach($fields as $k=>$v)
{
$stn->bindParam (":param$i", $fields[v]) ;
$i++;
}

```