} if ($classname != null) { if ($condition != null) { $classname_result = $db->get_all("SELECT item_id FROM lz_item WHERE classnum like '%" . $classname . "%' and (item_id in(" . $condition . ") )"); } else { $classname_result = $db->get_all("SELECT item_id FROM lz_item WHERE classnum like '%" . $classname . "%' "); } $result = my_array_add($result, $classname_result, 'item_id'); } //如果没输入查找, 就把条件当结果 if ($author == null && $institution == null && $name == null && $description == null && $keyword == null && $classname == null) { $result_con = $condition; } } //数组去重 $result = my_array_unique($result); //数组转为字符串,分item_id 和 aid两种情况 if ($result_con != null) { $result_string = $result_con; } else { $result_string = implode(',', $result); } //排序 if ($result_string != null) { $page_result = $db->get_all("SELECT* FROM (SELECT* FROM lz_item WHERE item_id in (" . $result_string . ")) as total"); } // 获取总数据量 $amount = count($page_result, 0); if ($result_string != null) { #echo "4 "; if ($sort_mode == "category") {
$command = "(/usr/bin/svn commit {$path} -m 'post-tag version change' --username {$svn_conf[$codebase_name]['username']} --password {$svn_conf[$codebase_name]['password']} --no-auth-cache --non-interactive > /dev/null) 3>&1 1>&2 2>&3"; echo $command . "\n"; echo shell_exec("{$command}"); //clean up version.txt temp folder $command = "rm -Rf {$path}"; echo $command . "\n"; echo shell_exec("{$command}"); // Create empty changelog.sql in trunk $repo = $svn_conf[$codebase_name]['url']; $username = $svn_conf[$codebase_name]['username']; $password = $svn_conf[$codebase_name]['password']; $local_path = '/tmp/tag' . rand(1000, 9999) . '/'; $repo_path = '/pages/dev/sql/' . $db_platform . '/changelog/'; $filename = 'changelog.sql'; // mkdir for changelog in the repository $temp = my_array_unique(explode('/', $repo_path)); foreach ($temp as $folder) { $mkdir_path .= '/' . $folder; $command = "svn mkdir {$repo}/trunk{$mkdir_path} -m x --username={$username} --password={$password} --non-interactive 2>&1"; //echo $command."\n"; shell_exec("{$command}"); } // create temporary checkout $command = "svn co {$repo}/trunk{$repo_path} {$local_path} --username={$username} --password={$password} --non-interactive 2>&1"; echo $command . "\n"; echo shell_exec("{$command}"); // create empty file $command = "touch {$local_path}{$filename}"; echo $command . "\n"; echo shell_exec("{$command}"); // add to working copy
<?php $input = array("a" => "green", "red", "b" => "green", "blue", "red"); function my_array_unique(array $arr) { $newArray = array(); foreach ($arr as $i => $iValue) { foreach ($arr as $j => $jValue) { if ($i == $j) { $newArray[$i] = $iValue; } if ($jValue == $iValue) { break; } } } return $newArray; } echo "Начальный массив<br>"; var_dump($input); echo "<br>*************my_array_unique:<br>"; $result = my_array_unique($input); var_dump($result); echo "<br>"; var_dump(array_unique($input)); echo "<br>**************array_unique";
echo "<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n<title>my_array_unique</title>\n</head>\n<body>"; $input = array(8, 2, 4, 8, "a" => "dfsf", 8, "red", 4, "b" => "green", 8, true, 4, "blue2", true, "red1", 6, 8); function my_array_unique($array) { $result = false; if (is_array($array)) { $result = array(); while (count($array)) { $same = array_keys($array, current($array), true); sort($same); $result[$same[0]] = $array[$same[0]]; for ($i = 0; $i <= count($same) - 1; $i++) { unset($array[$same[$i]]); } } } return $result; } if (my_array_unique($input)) { $my = my_array_unique($input); } else { die("Отсутствуют или некоректные входные данные!"); } $standart = array_unique($input); echo "<pre> Исходный массив<br>"; print_r($input); echo "<br>Стандартная функция<br>"; print_r($standart); echo "<br>Моя функция<br>"; print_r($my); echo "</body>\n</html>";
$test_array[] = array(2, 3, 4); $test_array[] = array(2, 3, 5); $test_array[] = 1.6; $test_array[] = 2.6; $test_array[] = 1.6; $test_array['fl'] = 3.6; $test_array['obj1'] = new Exception('TEST'); $test_array['obj2'] = new Exception('TEST'); $test_array['resource1'] = fopen("my_array_unique.php", "r"); $test_array['resource2'] = fopen("test.php", "r"); for ($i = 0; $i < $random_int_elements; $i++) { $test_array[] = mt_rand(0, $random_int_elements); } echo "<h1>Initial TEST ARRAY</h1>"; var_dump($test_array); echo "<h1>The result of array_unique function</h1>"; $start = microtime(true); $test_array_unique = array_unique($test_array); var_dump($test_array_unique); $time = microtime(true) - $start; printf('array_unique выполнялся %.4F сек.', $time); echo "<h1>The result of MY_array_unique function</h1>"; $start = microtime(true); try { $test_array_unique = my_array_unique($test_array); } catch (Exception $e) { echo $e->getMessage(); } var_dump($test_array_unique); $time = microtime(true) - $start; printf('my_array_unique выполнялся %.4F сек.', $time);
<?php $blog_article_id = $id; $tags = my_array_unique(explode(',', $_POST['article_tags'])); // print_r($_POST); foreach ($tags as $tag) { $tag = trim(strtolower($tag)); // echo $tag . ','; $SQL = "select id\n\t\t\tfrom blog_tag\n\t\t\twhere active = 1\n\t\t\tand blog_id = {$blog_id}\n\t\t\tand name = '{$tag}'"; $r = $db->Execute($SQL) or die("{$SQL}<br>" . $db->ErrorMsg()); if ($r->EOF) { // insert new blog_tag // echo 'inserting ' . $tag; $f = NULL; $f['blog_id'] = $blog_id; $f['name'] = $tag; $f['mod__person_id'] = $_SESSION['login']['person_id']; if ($_POST['debug']) { print_r($f); } $table = 'blog_tag'; $db->AutoExecute($table, $f, 'INSERT') or die($db->ErrorMsg()); $SQL = "SELECT currval('" . $table . "_id_seq') as id "; $s = $db->Execute($SQL); $blog_tag_id = $s->Fields('id'); if ($_POST['debug']) { echo "new '{$tag}' blog_tag_id: " . $blog_tag_id . "\n"; } } else { $blog_tag_id = $r->Fields('id'); }