$values) { foreach($values as $index => $value) { if ( ! isset($output[$index])) { $output[$index] = array(); } $output[$index][$append_key] = $value; } } return $output; } // -------------------------------------------------------------------------- /** * Get an array out of an multi-dimensional array based on a common * key * * @param array $array * @param string $key * @return array */ function array_pluck(Array $array, $key) { $output = array(); // No point iterating over an empty array if (empty($array)) return $array; foreach($array as $inner_array) { if (array_key_exists($key, $inner_array)) { $output[] = $inner_array[$key]; } } return $output; } // -------------------------------------------------------------------------- /** * Determine whether a value in the passed array matches the pattern * passed * * @param array $array * @param string $pattern * @return bool */ function regex_in_array(Array $array, $pattern) { if (empty($array)) return FALSE; foreach($array as $item) { if (is_scalar($item)) { if (preg_match($pattern, $item)) return TRUE; } } return FALSE; } // -------------------------------------------------------------------------- /** * Connection function * * Send an array or object as connection parameters to create a connection. If * the array or object has an 'alias' parameter, passing that string to this * function will return that connection. Passing no parameters returns the last * connection created. * * @param string|object|array $params * @return Query\Query_Builder|null */ function Query($params = '') { $cmanager = \Query\Connection_Manager::get_instance(); // If you are getting a previously created connection if (is_scalar($params)) { return $cmanager->get_connection($params); } elseif ( ! is_scalar($params) && ! is_null($params)) { $params_object = new stdClass(); foreach($params as $k => $v) { $params_object->$k = $v; } // Otherwise, return a new connection return $cmanager->connect($params_object); } // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd // End of common.php