title: Retrieving php array key and value from postgresql function parameter for database update
body: <p>I am trying to send an array of key value pairs to a postgresql function as parameter. The structure of the array is following - </p>
  
  <pre><code>array(10) { 
    ["OWNER"]=&gt; string(3) "ERP" 
    ["SOURCE"]=&gt; string(7) "Unknown" 
    ["PRIORITY"]=&gt; string(6) "Medium" 
    ["PREFLOC"]=&gt; string(5) "Dhaka" 
    ["PROBABLE"]=&gt; string(2) "50" 
    ["MAXSIZE"]=&gt; string(4) "1000" 
    ["MINSIZE"]=&gt; string(4) "2000" 
    ["INTAREA"]=&gt; string(14) "Dhaka, Gulshan" 
    ["CVALPRF"]=&gt; string(5) "Great" 
    ["OPPAMOUNT"]=&gt; string(3) "200" 
  }
  </code></pre>
  
  <p>And the function accepts a string array parameter like this</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION 
  document.update_doc_attrib_on_opportunity(p_org_id numeric, p_target_doc_code character varying, 
  p_target_doc_no numeric, p_doc_attribs character varying[])
  </code></pre>
  
  <p>Now I want to get the array sent to p_doc_attribs inside my function. Like for specific key name I need to insert the desired value in table. 
  The following query needs to be updated accordingly - </p>
  
  <pre><code>'UPDATE use_doc_attribute
          SET attrib_value = CASE WHEN attrib_code = ''PREFLOC''  THEN ''' || p_preferred_location || '''
                      WHEN attrib_code = ''PRIORITY'' THEN ''' || p_priority || '''
                      WHEN attrib_code = ''PROBABLE'' THEN ''' || p_probability || '''
                      WHEN attrib_code = ''SOURCE''   THEN ''' || p_source || '''
                      WHEN attrib_code = ''MAXSIZE''  THEN ''' || p_max_size || '''
                      WHEN attrib_code = ''MINSIZE''  THEN ''' || p_min_size || '''
                      WHEN attrib_code = ''INTAREA''  THEN ''' || p_interested_areas || '''
                      WHEN attrib_code = ''CVALPRF''  THEN ''' || p_client_value_profile || '''
                      ELSE attrib_value
                     END
          WHERE org_id = ' || p_org_id || '
          AND document_no = ' || p_target_doc_no || '
          AND document_code = ''' || p_target_doc_code || '''';
  </code></pre>
  
  <p>The attrib_code will contain the key and attrib_value for specific case will be the value retrieved from p_doc_attribs array.</p>