Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1.   /**
  2.    * Flattens and concatenates an array according to what QuickPay expects as parameters.
  3.    *
  4.    * @param array $parameters
  5.    *   The array to be flattened.
  6.    * @param string $prefix
  7.    *   The prefix to add in front of every key.
  8.    * @return array
  9.    *   Returns a flattened array with concatenated keys.
  10.    */
  11.   public function formatParameterArray(array $parameters, $prefix = '') {
  12.     $result = [];
  13.  
  14.     foreach ($parameters as $key => $value) {
  15.       if (empty($prefix)) {
  16.         $new_key = $key;
  17.       } else {
  18.         $new_key = $prefix.'['.$key.']';
  19.       }
  20.  
  21.       if (is_array($value)) {
  22.         $result = array_merge($result, $this->formatParameterArray($value, $new_key));
  23.       } else {
  24.         $result[$new_key] = $value;
  25.       }
  26.     }
  27.  
  28.     return $result;
  29.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement