* R::genSlots( array( 'a', 'b' ) );
*
*
* The statement in the example will produce the string:
* '?,?'.
*
* Another example, using a template string:
*
*
* R::genSlots( array('a', 'b'), ' IN( %s ) ' );
*
*
* The statement in the example will produce the string:
* ' IN( ?,? ) '.
*
* @param array $array array to generate question mark slots for
* @param string $template template to use
*
* @return string
*/
public static function genSlots( $array, $template = NULL )
{
$str = count( $array ) ? implode( ',', array_fill( 0, count( $array ), '?' ) ) : '';
return ( is_null( $template ) || $str === '' ) ? $str : sprintf( $template, $str );
}
/**
* Flattens a multi dimensional bindings array for use with genSlots().
*
* Usage:
*
*
* R::flat( array( 'a', array( 'b' ), 'c' ) );
*
*
* produces an array like: [ 'a', 'b', 'c' ]
*
* @param array $array array to flatten
* @param array $result result array parameter (for recursion)
*
* @return array
*/
public static function flat( $array, $result = array() )
{
foreach( $array as $value ) {
if ( is_array( $value ) ) $result = self::flat( $value, $result );
else $result[] = $value;
}
return $result;
}
}