/** * Converts the passed array to the necessary for prepared statement. * * If the array is associative then * it creates a :x,:y style string. If the array is numeric then creates a string with ? eg: * <pre> * $arr = array ( 'domain' => 0, 'length' => 1, 'tld' => 5, 'pricescore' => 2, 'intprice' => 4 ); * $params = array ( 'foo' => 'dummy1', 'bar' => 'dummy2' ); * echo 'INSERT INTO domain_info VALUES(' . DB::in ( $arr, $params ) . ')<br>'; * echo '<pre>'; print_r ( $params ); echo '</pre>'; * * $arr = array_values ( $arr ); * $params = array ( 'dummy1', 'dummy2' ); * echo 'INSERT INTO domain_info VALUES(' . DB::in ( $arr, $params ) . ')<br>'; * echo '<pre>'; print_r ( $params ); echo '</pre>'; * </pre> * @param mixed $values Values that will be in the IN. * @param mixed &$params Adds to the parameters. * * @since 1.0 * @return string */ public static function in($values, &$params = null) { if (!is_array($params)) { $params = []; } if (PHPExt::is_assoc($values)) { foreach ($values as $key => $val) { $params[$key] = $val; } return ':' . join(',:', array_keys($values)); } else { if (!is_array($values)) { $values = [$values]; } foreach ($values as $val) { $params[] = $val; } return join(',', array_fill(0, count($values), '?')); } }