3 namespace RedBeanPHP\Util;
5 use RedBeanPHP\OODB as OODB;
6 use RedBeanPHP\OODBBean as OODBBean;
7 use RedBeanPHP\RedException as RedException;
12 * This code was originally part of the facade, however it has
13 * been decided to remove unique features to service classes like
14 * this to make them available to developers not using the facade class.
16 * This is a helper or service class containing frequently used
17 * array functions for dealing with SQL queries.
19 * @file RedBeanPHP/Util/ArrayTool.php
20 * @author Gabor de Mooij and the RedBeanPHP Community
24 * copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community
25 * This source file is subject to the BSD/GPLv2 License that is bundled
26 * with this source code in the file license.txt.
31 * Generates question mark slots for an array of values.
33 * @param array $array array to generate question mark slots for
37 public static function genSlots( $array, $template = NULL )
39 $str = count( $array ) ? implode( ',', array_fill( 0, count( $array ), '?' ) ) : '';
40 return ( is_null( $template ) || $str === '' ) ? $str : sprintf( $template, $str );
44 * Flattens a multi dimensional bindings array for use with genSlots().
46 * @param array $array array to flatten
47 * @param array $result result array parameter (for recursion)
51 public static function flat( $array, $result = array() )
53 foreach( $array as $value ) {
54 if ( is_array( $value ) ) $result = self::flat( $value, $result );
55 else $result[] = $value;