public static function decrypt($text, $options = array()) { if (!function_exists('mcrypt_decrypt')) { throw new Alt_Exception("PHP Mcrypt extension is not enabled"); } $options = array_union($options, array('algorithm' => MCRYPT_RIJNDAEL_128, 'mode' => MCRYPT_MODE_CBC, 'key' => Alt::$config['app']['id'], 'iv' => Alt::$config['app']['id'])); return rtrim(mcrypt_decrypt($options['algorithm'], $options['key'], base64_decode($text), $options['mode'], $options['iv'] ? $options['iv'] : mcrypt_create_iv(mcrypt_get_iv_size($options['algorithm'], $options['mode']), MCRYPT_DEV_URANDOM)), ""); }
public function set_body($data = array()) { $data = array_union($data, $this->data); $body = ""; if (function_exists("http_build_query")) { $body = http_build_query($data); } else { foreach ($data as $key => $value) { $body .= $key . '=' . $value . '&'; } rtrim($body, '&'); } return $body; }
function jaccard_similarity($file1, $file2) { //get an array of all of the tokens in each file $tokens1 = tokenize_file($file1); $tokens2 = tokenize_file($file2); //make an intersection array and a union array $inter = array_intersection($tokens1, $tokens2); $union = array_union($tokens1, $tokens2); //similarity coefficient is sizeof(intersection)/sizeof(union) $jac = 0; if (sizeof($union) > 0) { $jac = sizeof($inter) / sizeof($union); } return $jac; }
public function connect() { if ($this->_connection) { return; } if (Alt_Database_Mysql::$_set_names === NULL) { // Determine if we can use mysql_set_charset(), which is only // available on PHP 5.2.3+ when compiled against Mysql 5.0+ Alt_Database_Mysql::$_set_names = !function_exists('mysqli_set_charset'); } // Extract the connection parameters, adding required variabels extract(array_union($this->_config['connection'], array('database' => '', 'hostname' => '', 'username' => '', 'password' => '', 'port' => 3306, 'persistent' => FALSE))); // Prevent this information from showing up in traces unset($this->_config['connection']['username'], $this->_config['connection']['password']); try { if ($persistent) { // Create a persistent connection $this->_connection = mysqli_connect("p:" . $hostname, $username, $password, null, $port); } else { // Create a connection and force it to be a new link $this->_connection = mysqli_connect($hostname, $username, $password, null, $port); } if (!$this->_connection) { throw new Alt_Exception(mysqli_connect_error()); } } catch (Exception $e) { // No connection exists $this->_connection = NULL; throw new Alt_Exception($e->getMessage()); } // \xFF is a better delimiter, but the PHP driver uses underscore $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password); $this->_select_db($database); if (!empty($this->_config['charset'])) { // Set the character set $this->set_charset($this->_config['charset']); } if (!empty($this->_config['connection']['variables'])) { // Set session variables $variables = array(); foreach ($this->_config['connection']['variables'] as $var => $val) { $variables[] = 'SESSION ' . $var . ' = ' . $this->quote($val); } mysqli_query($this->_connection, 'SET ' . implode(', ', $variables)); } }
public function connect() { if ($this->_connection) { return; } // Extract the connection parameters, adding required variabels extract(array_union($this->_config['connection'], array('dsn' => '', 'username' => NULL, 'password' => NULL, 'persistent' => FALSE))); // Clear the connection parameters for security unset($this->_config['connection']); // Force PDO to use exceptions for all errors $options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; if (!empty($persistent)) { // Make the connection persistent $options[PDO::ATTR_PERSISTENT] = TRUE; } try { // Create a new PDO connection $this->_connection = new PDO($dsn, $username, $password, $options); } catch (PDOException $e) { throw new Alt_Exception($e->getMessage()); } }
function array_dif(array $a, array $b) { if (count($a) == 0 or count($b) == 0) { return array_union($a, $b); } $c = array_diff($a, $b); $d = array_diff($b, $a); $e = array_union($c, $d); return $e; }
function array_union() { $argsCount = func_num_args(); if ($argsCount < 2) { return false; } else { if (2 === $argsCount) { list($arr1, $arr2) = func_get_args(); while (list($k, $v) = each($arr2)) { if (!in_array($v, $arr1)) { $arr1[] = $v; } } return $arr1; } else { // 三个以上的数组合并 $arg_list = func_get_args(); $all = call_user_func_array('array_union', $arg_list); return array_union($arg_list[0], $all); } } }
function step($string, $cnf) { $cyk = cyk($string, $cnf); for ($i = 1; $i <= count($string); $i++) { echo "T<sub>" . $i . "1</sub> = " . $string[$i - 1] . " = " . implode(", ", cari($string[$i - 1], $cnf)) . "<br>"; } echo "<br>"; for ($j = 2; $j <= count($string); $j++) { for ($i = 1; $i <= count($string) - $j + 1; $i++) { $tot = array(); for ($k = 1; $k <= $j - 1; $k++) { $gab = array_union($cyk[$k][$i], $cyk[$j - $k][$i + $k]); $gabungan = implode(", ", $gab); $hsl = cariArray(array_union($cyk[$k][$i], $cyk[$j - $k][$i + $k]), $cnf); $tot = array_merge($tot, $hsl); $hasil = implode(", ", $hsl); if ($hasil == "") { $hasil = "∅"; } echo "T<sub>" . $i . $j . "</sub> = T<sub>" . $i . $k . "</sub> - T<sub>" . ($i + $k) . ($j - $k) . "</sub> = " . $gabungan . " = " . $hasil; echo "<br>"; } if ($j > 2) { $total = implode(", ", array_unique($tot)); if ($total == "") { $total = "∅"; } echo "<b>T<sub>" . $i . $j . "</sub> = " . $total . "</b>"; echo "<br>"; } } echo "<br>"; } }
function testSetUnionStore() { $setA = RC::setAddAndReturn($this->redis, 'setA', array(0, 1, 2, 3, 4, 5, 6)); $setB = RC::setAddAndReturn($this->redis, 'setB', array(1, 3, 4, 6, 9, 10)); $this->assertEquals(count($setA), $this->redis->sunionstore('setC', 'setA')); $this->assertTrue(RC::sameValuesInArrays($setA, $this->redis->smembers('setC'))); $this->redis->del('setC'); $this->assertEquals(9, $this->redis->sunionstore('setC', 'setA', 'setB')); $this->assertTrue(RC::sameValuesInArrays(array_union($setA, $setB), $this->redis->smembers('setC'))); // non-existing keys are considered empty sets $this->redis->del('setC'); $this->assertEquals(0, $this->redis->sunionstore('setC', 'setDoesNotExist')); $this->assertFalse($this->redis->exists('setC')); $this->assertEquals(0, $this->redis->scard('setC')); // existing keys are replaced by SUNIONSTORE $this->redis->set('foo', 'bar'); $this->assertEquals(count($setA), $this->redis->sunionstore('foo', 'setA')); // wrong type $this->redis->set('foo', 'bar'); RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, p_anon("\$test", "\n \$test->redis->sunionstore('setA', 'foo');\n ")); }
/** * @param array $array2 * @return callable */ function array_union_dg($array2) { return function ($array1) use($array2) { return array_union($array1, $array2); }; }